Source for file UserDataContainer.abstract.php

Documentation is available at UserDataContainer.abstract.php

  1. <?php
  2.  
  3. /**
  4. * A UserDataContainer is like a DataContainer, but is targeted towards data
  5. * used from http forms instead of configuration options in a script.
  6. *
  7. * @package harmoni.utilities
  8. *
  9. * @copyright Copyright &copy; 2005, Middlebury College
  10. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  11. *
  12. * @version $Id: UserDataContainer.abstract.php,v 1.6 2007/09/05 19:55:22 adamfranco Exp $
  13. */
  14. class UserDataContainer extends DataContainer {
  15. /**
  16. * @access private
  17. * @var array $_setFields An array of fields that have been set.
  18. ***/
  19. var $_setFields;
  20. /**
  21. * The set method sets the value for a field while checking constrictions.
  22. * @param string $field The field to set.
  23. * @param mixed $val The value to set $field to.
  24. * @access public
  25. * @return boolean True if setting $field succeeds.
  26. ***/
  27. function set( $field, $val ) {
  28. // first check if this is a valid field.
  29. if (!in_array($field,$this->_ruleSet->getKeys())) {
  30. // no good
  31. throwError( new Error(get_class($this)." - can not set key '$field' because it is not a valid key!","UserDataContainer",true));
  32. return false;
  33. }
  34. if ($this->_ruleSet->validate($field, $val)) {
  35. $this->_fieldSet->set($field, $val);
  36. $this->_setFields[$field] = true;
  37. return true;
  38. }
  39. return false;
  40. }
  41. /**
  42. * Checks to see if this field has been set.
  43. * @access public
  44. * @return boolean
  45. ***/
  46. function hasValue( $field ) {
  47. return isset($this->_setFields[$field]);
  48. }
  49. /**
  50. * Returns the number of fields for which new values have been specified.
  51. * @access public
  52. * @return integer
  53. ***/
  54. function countChanged() {
  55. return count($this->_setFields);
  56. }
  57. /**
  58. * Populates the attached FieldSet without processing rules or keeping track
  59. * of what has been set.
  60. * @param array $data An array of key=>value pairs.
  61. * @access public
  62. * @return void
  63. ***/
  64. function populate($data) {
  65. foreach($this->_ruleSet->getKeys() as $key) {
  66. $this->_fieldSet->set($key,$data[$key]);
  67. }
  68. }
  69. }
  70.  
  71. ?>

Documentation generated on Wed, 19 Sep 2007 10:27:39 -0400 by phpDocumentor 1.3.0RC3