PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/fields/class.dbTextSelectField.php

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