/**
  * Transform the \Node entity.
  *
  * @param \Node $model
  *
  * @return array
  */
 public function transformData($model)
 {
     return $model->toArray();
 }
 /**
  * Transform the \Node entity.
  *
  * @param \Node $model
  *
  * @return array
  */
 public function transformData($model)
 {
     $data = $model->toArray();
     $data['parent_node'] = $model->parent_node ?: 0;
     return $data;
 }
 public function nodeToPersistentArray(Node $obj)
 {
     $persistent = array_intersect_key($obj->toArray(), array_flip($this->NodeDBMeta->getPersistentFields()));
     $persistent['ElementID'] = $obj->getNodeRef()->getElement()->getElementID();
     return $persistent;
 }
<?php

require_once 'Node.php';
$nodes = array();
$node = new Node("Titutlo A1", "A1", true, true, true, array(new Node("Titutlo A1.B1", "A1.B1", true, true, true), new Node("Titutlo A1.B2", "A1.B2", true, true, true, array(new Node("Titutlo A1.B2.C1", "A1.B2.C1", true, true, true)))));
$node2 = new Node("Titutlo A2", "A2", true, true, true, array(new Node("Titutlo A2.B1", "A2.B1", true, true, true, array(new Node("Titutlo A2.B1.C1", "A2.B1.C1"), new Node("Titutlo A2.B1.C2", "A2.B1.C2"), new Node("Titutlo A2.B1.C3", "A2.B1.C3")))));
$node3 = new Node("Titutlo A3", "A3");
array_push($nodes, $node->toArray());
array_push($nodes, $node2->toArray());
array_push($nodes, $node3->toArray());
echo json_encode($nodes);
Beispiel #5
0
        $pass = false;
        echo "Must return false\n";
    }
    // Print
    $root->print_r();
    return $pass;
};
$tests['fromArray toArray'] = function () {
    $pass = true;
    // Prepare
    $json = '{"id":"c170ad596fb6f987f0b34bf58099ca63","properties":[],"children":{"a":{"id":"2d63f222710222663373b0692b273103","properties":[],"children":{"b":{"id":"dc3a2e4652f068bad6f78e71920483f8","properties":[],"children":{"c":{"id":"63f5f8032383f518381541e2053b9213","properties":[],"children":[]},"d":{"id":"1f3b9cf313b126f9ed03739730d58eed","properties":[],"children":[]}}},"e":{"id":"5049e43d9fd9576aa0e715d9bd8dea20","properties":[],"children":{"f":{"id":"f8a45a93ed68521a7d4c23b7918b13b3","properties":[],"children":[]},"g":{"id":"a95c67d9ebdbc4f3fb175242fb1307eb","properties":[],"children":[]}}}}}}}';
    $array = json_decode($json, true);
    // Run
    $root = new Node();
    $root->fromArray($array);
    $result = $root->toArray();
    $result_json = json_encode($result);
    // Check
    if ($json !== $result_json) {
        $pass = false;
        echo "Serialization fail\n";
    }
    // Print
    echo "{$json}\n{$result_json}";
    return $pass;
};
$tests['get property'] = function () {
    $pass = true;
    // Prepare
    $hash_red = md5(microtime());
    $hash_blue = md5(microtime());
Beispiel #6
0
 /**
  * @test
  */
 public function getThePropertiesAsAnArray()
 {
     $properties = array('id' => 'xyz', 'foo' => 'bar', 'gggg' => 123);
     $node = new Node($properties);
     $this->assertEquals($properties, $node->toArray());
 }