<?php
/**
*
*
* @version $Id$
* @copyright 2003
**/
class ObjectAgent {
var $object = "";
function ObjectAgent($_object) {
$this->object = $_object;
}
function fill($_data) {
foreach($_data as $field => $value) {
if($field == $this->object->primaryKey) {
$setMethod = "set".ucfirst($field);
} else {
$property = $this->object->fields[$field];
$setMethod = "set".ucfirst($property);
}
$this->object->$setMethod($value);
}
$this->object->setNewRecord(false);
return $this->object;
}
function clear($_fields) {
foreach($_fields as $field => $property) {
$setMethod = "set".ucfirst($property);
$this->object->$setMethod("");
}
$primaryKey = $this->object->primaryKey;
$setMethod = "set".ucfirst($primaryKey);
$this->object->$setMethod("");
if (!empty($this->object->oneToMany)) {
foreach($this->object->oneToMany as $table => $linkOn) {
$this->object->$table = "";
$objectArray = $this->object->objectArrayMap[$table];
$this->object->$objectArray = "";
}
}
$this->object->setNewRecord(true);
return $this->object;
}
}
?>