* @copyright 2004/2005 by http://wombat.exit0.net * @package wombatSite * @subpackage formDatasource */ /** * datasource for Wombat framework * * @version 0.2.1 * @package wombatSite * @subpackage formDatasource */ class wbFormDatasource_Table extends wbFormDatasource { /** * default values of used attributes * @access private * @var array $_params */ var $_atts = array( 'table' => 'user', 'format' => '%s', 'fields' => 'user', 'empty' => 'no', 'emptyvalue' => '', 'emptylabel' => '-------------', 'onlymy' => 'no' ); /** * gsDatasource object * @access private */ var $_ds = null; /** * returns values suitable for patForms-Elements * * @access public * @return boolean $result true on success */ function getValues() { // select custom format $format = $this->_atts['format']; $fields = explode( ',', $this->_atts['fields'] ); $order = $fields[0]; $table = $this->_atts['table']; $values = array(); // allow empty values if( isset( $this->_atts['empty'] ) && $this->_atts['empty'] === 'yes' ) { $value = $this->_atts['emptyvalue']; $label = $this->_atts['emptylabel']; array_push( $values, array( 'value' => $value, 'label' => $label ) ); } if( !$this->_ds ) { $this->_ds =& wbFactory::singleton( 'wbDatasource' ); } $primary = $this->_ds->getPrimaryKey( $table ); $clause = array(); if( isset( $this->_atts['onlymy'] ) && $this->_atts['onlymy'] == 'yes' ) { $user = wbFactory::singleton( 'wbUser' ); $clause[] = array( 'field' => $this->_ds->getPrimaryKey( 'user' ), 'value' => $user->GetUserId() ); } $entries = $this->_ds->getEntries( $table, null, $clause ); foreach( $entries as $entry ) { $myFields = array(); foreach( $fields as $f ) { array_push( $myFields, $entry[$f] ); } $value = array(); $value['value'] = $entry[$primary]; $value['label'] = vsprintf( $format, $myFields ); array_push( $values, $value ); } return $values; } } ?>