* @license PHP License * @package WB * @subpackage db */ WBClass::load('WBDatasource_FormAttribute'); /** * Populate form element's values from any table * * Use datasource view to populate list * * @version 0.1.0 * @package WB * @subpackage db */ class WBDatasource_FormAttribute_View extends WBDatasource_FormAttribute { /** * configuration parameter * @var array */ protected $config = array( 'view' => 'adminuser', 'valuecolumn' => 'uid', 'labelcolumns' => array('surname', 'forename', 'nickname'), 'labelformat' => '%s, %s (%s)' ); /** * view * @var WBDatasource_Vier */ protected $view; /** * view * @var WBDatasource_Renderer_Array */ protected $rendy; /** * get attribute's value * * Use dicktionary to fetch list of values * * @param mixed $current actual attribute value * @return array */ protected function getAttributeValue($current) { $this->view = WBClass::create('WBDatasource_View'); $this->randy = WBClass::create('WBDatasource_Renderer_Array'); if (!is_array($current)) { $current = array(); } $this->view->setRenderer($this->randy); $this->view->render('view/' . $this->config['view']); $list = $this->randy->getList(); if (empty($list)) { return $current; } // append list $primary = $this->config['valuecolumn']; 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; } } ?>