* @license PHP License * @package WB * @subpackage db */ WBClass::load('WBDatasource_FormAttribute' , 'WBException_Call' ); /** * Populate form element's values from Dictionary * * Use dictionary lists to fill values * * @version 0.1.0 * @package WB * @subpackage db */ class WBDatasource_FormAttribute_Dictionary extends WBDatasource_FormAttribute { /** * configuration parameter * @var array */ protected $config = array( 'dict' => 'Country' ); /** * dictionary * @var WBDictionary */ protected $dict; /** * get attribute's value * * Use dicktionary to fetch list of values * * @param mixed $current actual attribute value * @return array */ protected function getAttributeValue($current) { if (!is_array($current)) { $current = array(); } $this->dict = WBClass::create('WBDictionary_' . $this->config['dict']); try { $list = $this->dict->getList(); } catch(WBException_Call $e) { return $current; } if (empty($list)) { return $current; } // append list foreach ($list as $v => $l) { $current[] = array( 'value'=> $v, 'label' => $l ); } return $current; } } ?>