* @license PHP License * @package WB * @subpackage db */ WBClass::load('WBDatasource_FormAttribute'); /** * Populate form element's values from any table * * Use table data to populate values * * @version 0.2.0 * @package WB * @subpackage db */ class WBDatasource_FormAttribute_Table extends WBDatasource_FormAttribute { /** * configuration parameter * @var array */ protected $config = array( 'table' => 'group', 'labelcolumns' => array('groupname'), 'labelformat' => '%s', 'clause' => array(), 'order' => array() ); /** * table * @var WBDatasource_Table */ protected $table; /** * get attribute's value * * Use dicktionary to fetch list of values * * @param mixed $current actual attribute value * @return array */ protected function getAttributeValue($current) { $this->table = WBClass::create('WBDatasource_Table'); if (!is_array($current)) { $current = array(); } if (!is_array($this->config['clause'])) { $this->config['clause'] = array(); } $options = array('limit' => 0); if (!empty($this->config['order'])) { $options['order'] = $this->config['order']; } $list = $this->table->get($this->config['table'], null, null, $this->config['clause'], $options); if (empty($list)) { return $current; } // append list $primary = $this->table->getIdentifier($this->config['table']); foreach ($list as $v => $l) { $cols = array(); foreach ($this->config['labelcolumns'] as $lc) { $cols[] = $l[$lc]; } $current[] = array( 'value' => $l[$primary], 'label' => vsprintf($this->config['labelformat'], $cols) ); } return $current; } } ?>