C_DataMapper_Model

Class C_DataMapper_Model.

Defined (1)

The class is defined in the following location(s).

/products/photocrati_nextgen/modules/datamapper/package.module.datamapper.php  
  1. class C_DataMapper_Model extends C_Component 
  2. var $_mapper; 
  3. var $_stdObject; 
  4. /** 
  5. * Define the model 
  6. */ 
  7. function define($mapper = NULL, $properties = array(), $context = FALSE) 
  8. parent::define($context); 
  9. $this->add_mixin('Mixin_Validation'); 
  10. $this->add_mixin('Mixin_DataMapper_Model_Instance_Methods'); 
  11. $this->add_mixin('Mixin_DataMapper_Model_Validation'); 
  12. $this->implement('I_DataMapper_Model'); 
  13. /** 
  14. * Creates a new entity for the specified mapper 
  15. * @param C_DataMapper_Driver_Base $mapper 
  16. * @param array|stdClass $properties 
  17. * @param string $context 
  18. */ 
  19. function initialize($mapper = NULL, $properties = FALSE) 
  20. $this->_mapper = $mapper; 
  21. $this->_stdObject = $properties ? (object) $properties : new stdClass(); 
  22. parent::initialize(); 
  23. if (!$this->has_default_values()) { 
  24. $this->set_defaults(); 
  25. $this->_stdObject->__defaults_set = TRUE; 
  26. function has_default_values() 
  27. return isset($this->_stdObject->__defaults_set) && $this->_stdObject->__defaults_set == TRUE; 
  28. /** 
  29. * Gets the data mapper for the entity 
  30. * @return C_DataMapper_Driver_Base 
  31. */ 
  32. function get_mapper() 
  33. return $this->_mapper; 
  34. /** 
  35. * Gets a property of the model 
  36. */ 
  37. function &__get($property) 
  38. if (isset($this->_stdObject->{$property})) { 
  39. $retval =& $this->_stdObject->{$property}; 
  40. return $retval; 
  41. } else { 
  42. // We need to assign NULL to a variable first, since only 
  43. // variables can be returned by reference 
  44. $retval = NULL; 
  45. return $retval; 
  46. /** 
  47. * Sets a property for the model 
  48. */ 
  49. function &__set($property, $value) 
  50. $retval = $this->_stdObject->{$property} = $value; 
  51. return $retval; 
  52. function __isset($property_name) 
  53. return isset($this->_stdObject->{$property_name}); 
  54. /** 
  55. * Saves the entity 
  56. * @param type $updated_attributes 
  57. */ 
  58. function save($updated_attributes = array()) 
  59. $this->update_attributes($updated_attributes); 
  60. return $this->get_mapper()->save($this->get_entity()); 
  61. /** 
  62. * Updates the attributes for an object 
  63. */ 
  64. function update_attributes($array = array()) 
  65. foreach ($array as $key => $value) { 
  66. $this->_stdObject->{$key} = $value; 
  67. /** 
  68. * Sets the default values for this model 
  69. */ 
  70. function set_defaults() 
  71. $mapper = $this->get_mapper(); 
  72. if ($mapper->has_method('set_defaults')) { 
  73. $mapper->set_defaults($this); 
  74. /** 
  75. * Destroys or deletes the entity 
  76. */ 
  77. function destroy() 
  78. return $this->get_mapper()->destroy($this->_stdObject); 
  79. /** 
  80. * Determines whether the object is new or existing 
  81. * @return type 
  82. */ 
  83. function is_new() 
  84. return $this->id() ? FALSE : TRUE; 
  85. /** 
  86. * Gets/sets the primary key 
  87. */ 
  88. function id($value = NULL) 
  89. $key = $this->get_mapper()->get_primary_key_column(); 
  90. if ($value) { 
  91. $this->__set($key, $value); 
  92. return $this->__get($key);