PageRenderTime 617ms CodeModel.GetById 187ms RepoModel.GetById 18ms app.codeStats 0ms

/lib/fields/class.dbRadioButton.php

https://github.com/reshadf/Library
PHP | 81 lines | 39 code | 9 blank | 33 comment | 4 complexity | 7b55351ab73c00bd4fcda34e83f3205c MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * class dbRadioButton
  4. *
  5. * Create a Radio button field from records retrieved from the db
  6. *
  7. * @author Johan Wiegel
  8. * @package FormHandler
  9. * @subpackage Fields
  10. * @since 10-04-2008
  11. */
  12. class dbRadioButton extends RadioButton
  13. {
  14. var $_oDb;
  15. /**
  16. * dbCheckBox::dbCheckBox()
  17. *
  18. * Public constructor: create a new db RadioButton object
  19. *
  20. * @param object &$oForm: the form where the datefield is located on
  21. * @param string $sName: the name of the datefield
  22. * @param object $oDb: object of the database handler
  23. * @param string $sTable: the table to get the fields from
  24. * @param mixed $mFields: array of string with the names of the fields which data we should get
  25. * @param string $sExtraSQL: extra SQL statements
  26. * @return dbRadioButton
  27. * @access public
  28. * @author Johan Wiegel
  29. */
  30. function dbRadioButton( &$oForm, $sName, &$oDb, $sTable, $mFields, $sExtraSQL = null, $sMask = null )
  31. {
  32. // call the constructor of the selectfield
  33. parent::RadioButton( $oForm, $sName, '' );
  34. // make sure that the fields are set in an array
  35. $aFields = !is_array($mFields) ? array( $mFields ) : $mFields;
  36. $this -> useArrayKeyAsValue( sizeof( $aFields) == 2 );
  37. // generate the query to retrieve the records
  38. $sQuery =
  39. 'SELECT '. implode(', ', $aFields).
  40. ' FROM '. $oDb->quote( $sTable).' '.$sExtraSQL;
  41. // get the records and load the options
  42. //$this->_aOptions = is_array($aMergeArray) ? $aMergeArray : array();
  43. // execute the query
  44. $sql = $oDb->query( $sQuery );
  45. // query succeeded
  46. if( $sql )
  47. {
  48. while( $row = $oDb->getRecord( $sql ) )
  49. {
  50. if( sizeof( $row ) == 1 )
  51. {
  52. $this->_aOptions[] = array_shift( $row );
  53. }
  54. else
  55. {
  56. $this->_aOptions[array_shift( $row )] = array_shift( $row );
  57. }
  58. }
  59. }
  60. // query failed
  61. else
  62. {
  63. trigger_error(
  64. "Error, could not retrieve records.<br '. FH_XHTML_CLOSE .'>\n".
  65. "Error message: ". $oDb->getError()."<br '. FH_XHTML_CLOSE .'>\n".
  66. "Query: ". $sQuery,
  67. E_USER_WARNING
  68. );
  69. }
  70. }
  71. }
  72. ?>