forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxModelCodec.php
More file actions
92 lines (82 loc) · 1.99 KB
/
mxModelCodec.php
File metadata and controls
92 lines (82 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* Copyright (c) 2006-2013, Gaudenz Alder
*/
class mxModelCodec extends mxObjectCodec
{
/**
* Class: mxModelCodec
*
* Codec for <mxGraphModels>. This class is created and registered
* dynamically at load time and used implicitly via <mxCodec>
* and the <mxCodecRegistry>.
*
* Constructor: mxObjectCodec
*
* Constructs a new codec for the specified template object.
* The variables in the optional exclude array are ignored by
* the codec. Variables in the optional idrefs array are
* turned into references in the XML. The optional mapping
* may be used to map from variable names to XML attributes.
*
* Parameters:
*
* template - Prototypical instance of the object to be
* encoded/decoded.
* exclude - Optional array of fieldnames to be ignored.
* idrefs - Optional array of fieldnames to be converted to/from
* references.
* mapping - Optional mapping from field- to attributenames.
*/
function mxModelCodec($template)
{
parent::mxObjectCodec($template);
}
/**
* Overrides <mxObjectCodec.encodeObject>.
*/
function encodeObject($enc, $obj, $node)
{
$rootNode = $enc->document->createElement("root");
$enc->encodeCell($obj->getRoot(), $rootNode);
$node->appendChild($rootNode);
}
/**
* Override <mxObjectCodec.decodeChild>.
*/
function decodeChild($dec, $child, &$obj)
{
if ($child->nodeName == "root")
{
$this->decodeRoot($dec, $child, $obj);
}
else
{
parent::decodeChild($dec, $child, $obj);
}
}
/**
* Override <mxObjectCodec.decodeRoot>.
*/
function decodeRoot($dec, $root, $model)
{
$rootCell = null;
$tmp = $root->firstChild;
while (isset($tmp))
{
$cell = $dec->decodeCell($tmp);
if (isset($cell) && $cell->getParent() == null)
{
$rootCell = $cell;
}
$tmp = $tmp->nextSibling;
}
// Sets the root on the model if one has been decoded
if (isset($rootCell))
{
$model->setRoot($rootCell);
}
}
}
mxCodecRegistry::register(new mxModelCodec(new mxGraphModel()));
?>