Skip to content
Snippets Groups Projects
Commit cf470bc4 authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

No commit message

No commit message
parent 1aeed621
No related branches found
No related tags found
No related merge requests found
......@@ -8,11 +8,13 @@ class DataObject
private $schemaPath;
private $parentObject;
private $storage;
private $changes = array();
public function DataObject($name, $schemaPath)
{
$this->name = $name;
$this->schemaPath = $schemaPath;
$this->changes[] = new DataObjectChange(DataObjectChange::CREATE);
}
public function setParentObject($parentObject)
......@@ -40,6 +42,7 @@ class DataObject
}
} elseif(is_scalar($value) || !$value) {
//echo "<br/>Adding scalar $name = $value";
$this->changes[] = new DataObjectChange(DataObjectChange::UPDATE, $name, (string)$this->storage[$name], $value);
$this->storage[$name]->setValue($value);
}
}
......@@ -96,6 +99,14 @@ class DataObject
return $return;
}
public function getChanges()
{
return $this->changes;
}
//*************************************************************************
// XML
//*************************************************************************
public function asXmlDocument()
{
$Document = new DOMDocument();
......
......@@ -7,6 +7,7 @@ class DataObjectArray
private $schemaPath;
private $arraySchemaPath;
private $parentObject;
private $changes;
public function DataObjectArray($name, $schemaPath, $arraySchemaPath)
{
......@@ -15,6 +16,7 @@ class DataObjectArray
$this->arraySchemaPath = $arraySchemaPath;
$this->setFlags(ArrayObject::ARRAY_AS_PROPS);
$this->setFlags(ArrayObject::STD_PROP_LIST);
$this->changes[] = new DataObjectChange(DataObjectChange::CREATE);
}
public function setParentObject($parentObject)
......@@ -22,10 +24,22 @@ class DataObjectArray
$this->parentObject = $parentObject;
}
public function append($childObject)
public function append($childObject, $silent=false)
{
$this->offsetSet(null, $childObject);
$childObject->setParentObject($this->parentObject);
if(!$silent) {
$this->changes[] = new DataObjectChange(DataObjectChange::CREATE, $childObject->name, null, serialize($childObject));
}
}
public function remove($offset)
{
$objectBefore = $this->offsetGet($offset);
$this->offsetUnset($offset);
if(!$silent) {
$this->changes[] = new DataObjectChange(DataObjectChange::DELETE, $objectBefore->name, serialize($objectBefore));
}
}
public function __get($name) {
......@@ -57,5 +71,9 @@ class DataObjectArray
}
return $return;
}
public function getChanges()
{
return $this->changes;
}
}
\ No newline at end of file
<?php
class DataObjectChange
{
const NONE = 0;
const CREATE = 1;
const READ = 2;
const UPDATE = 3;
const DELETE = 4;
private $timestamp;
private $type;
private $name;
private $ValueBefore;
private $valueAfter;
public function DataObjectChange($type, $name=false, $valueBefore=false, $valueAfter=false)
{
$this->type = $type;
$this->timestamp = date('d-m-y h:i:s') ;
$this->name = $name;
$this->valueBefore = $valueBefore;
$this->valueAfter = $valueAfter;
}
public function __get($name)
{
return $this->$name;
}
}
......@@ -16,6 +16,8 @@ class dataObjectController extends DOMDocument
require_once 'core/tests/class/DataObject.php';
require_once 'core/tests/class/DataObjectProperty.php';
require_once 'core/tests/class/DataObjectChange.php';
require_once 'core/tests/class/DataAccessService_Database.php';
$this->dataAccessService_Database = new dataAccessService_Database();
......@@ -121,7 +123,7 @@ class dataObjectController extends DOMDocument
for($i=0; $i<count($objectDatas); $i++) {
$objectData = $objectDatas[$i];
$itemDataObject = $this->instanciateDataObject($schemaPath);
$dataObject->append($itemDataObject);
$dataObject->append($itemDataObject, $silent=true);
//echo "<br/> Result has " . count($objectData) . " properties for object #$i of array";
$this->loadProperties($itemDataObject, $objectData);
$this->loadChildren($itemDataObject);
......@@ -152,7 +154,8 @@ class dataObjectController extends DOMDocument
break;
}
}
//*************************************************************************
// PUBLIC DAS FUNCTIONS
//*************************************************************************
......@@ -212,7 +215,8 @@ class dataObjectController extends DOMDocument
else return $objectSchema->name;
}
public function getContentLabels($objectName) {
public function getContentLabels($objectName)
{
$objectSchema = $this->schema->getObjectSchema($objectName);
$childElements = $objectSchema->getChildElements();
for($i=0; $i<$childElements->length;$i++) {
......
......@@ -34,10 +34,9 @@ class DataObjectProperty
}
}
public function setValue($value)
{
$this->storage = $value;
{
$this->storage = $value;
}
public function __toString()
......
......@@ -32,7 +32,7 @@ class DataObjectValidatorError
function DataObjectValidatorError($libXMLError)
{
$this->level = $libXMLError->level;
$this->code = $libXMLError->code;
$this->code = 'XML-' . $libXMLError->code;
$this->message = $libXMLError->message;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment