<?php
/* Please see the README and LICENSE files. */
/**
* Represents a specific group of information. A data object
*/
class Data_Model {
/**
* The attributes associated with this
* @var Data_Attribute[]
*/
protected $attributes = array();
/**
* The name of this object
* @var String
*/
protected $name;
/**
* @param String $name
*/
public function __construct($name){
$this->name = $name;
}
/**
* Adds an attribute to the object
* @param Data_Attribute $attribute
* @param String $name
*/
public function add_attribute($attribute,$name=NULL){
$this->attributes[$name==NULL?$attribute->name:$name] = $attribute;
}
/**
* Gets an attribute
* @param String $name
* @return Data_Attibute
*/
public function get_attribute($name){
if(array_key_exists($name)){
return $this->attributes[$name];
}
}
/**
* Gets all of the attributes
* @return Data_Attribute[]
*/
public function get_attributes(){
return $this->attributes;
}
/**
* Allows for -> referencing of attributes as a shortcut
* Ex.
* $model->attributeFoo->value
*
* @param String $name Whatever comes after the ->
* @return Mixed
*/
public function __get($name){
switch($name){
case "name":
case "attributes":
return $this->$name;
break;
default:
return @$this->attributes[$name];
}
}
/**
* Allows for -> setting of attributes as a shortcut
* Ex.
* $model->attribute->value = $val
*
* @param String $name Whatever comes after the ->
* @param Mixed $value Whatever is after the =
*/
public function __set($name,$value){
# TODO
}
/**
* Check if the model has changed in storage
* @return Boolean
*/
public function has_changed(){
foreach($this->attributes as $attribute){
if($attribute->has_changed()){
return true;
}
}
}
}
?>