public function testSetDataSource() { $list = new TDropDownList(); $data = array('a' => 1, 'b' => 2, 'c' => 3); $list->setDataSource($data); $list->dataBind(); $items = $list->getItems(); $this->assertTrue($items instanceof TListItemCollection); $expected_keys = array_keys($data); $i = 0; foreach ($items as $item) { $this->assertEquals($expected_keys[$i], $item->getValue()); $this->assertEquals((string) $data[$expected_keys[$i]], $item->getText()); $i++; } }
protected function createTimeControl($container, $column, $record) { $value = $this->getRecordPropertyValue($column, $record); $hours = array(); for ($i = 0; $i < 24; $i++) { $hours[] = str_pad($i, 2, '0', STR_PAD_LEFT); } $mins = array(); for ($i = 0; $i < 60; $i++) { $mins[] = str_pad($i, 2, '0', STR_PAD_LEFT); } $hour = intval(@date('H')); $min = intval(@date('i')); $sec = intval(@date('s')); if (!empty($value)) { $match = array(); if (preg_match('/(\\d+):(\\d+):?(\\d+)?/', $value, $match)) { $hour = $match[1]; $min = $match[2]; if (isset($match[3])) { $sec = $match[3]; } } } $hcontrol = new TDropDownList(); $hcontrol->setDataSource($hours); $hcontrol->setID(self::DEFAULT_ID); $hcontrol->dataBind(); $hcontrol->setSelectedValue(intval($hour)); $container->Controls[] = $hcontrol; $container->Controls[] = ' : '; $mcontrol = new TDropDownList(); $mcontrol->setDataSource($mins); $mcontrol->dataBind(); $mcontrol->setID('scaffold_time_min'); $mcontrol->setSelectedValue(intval($min)); $container->Controls[] = $mcontrol; $container->Controls[] = ' : '; $scontrol = new TDropDownList(); $scontrol->setDataSource($mins); $scontrol->dataBind(); $scontrol->setID('scaffold_time_sec'); $scontrol->setSelectedValue(intval($sec)); $container->Controls[] = $scontrol; return array($hcontrol, $mcontrol, $scontrol); }
/** * Updates the client-side options if the item list has changed after the OnLoad event. */ public function onPreRender($param) { parent::onPreRender($param); $this->getAdapter()->updateListItems(); }