forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxCellPath.php
More file actions
102 lines (90 loc) · 1.87 KB
/
mxCellPath.php
File metadata and controls
102 lines (90 loc) · 1.87 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
93
94
95
96
97
98
99
100
101
102
<?php
/**
* Copyright (c) 2006-2013, Gaudenz Alder
*/
class mxCellPath
{
/**
* Class: mxCellPath
*
* Implements a mechanism for temporary cell Ids.
*
* Variable: codecs
*
* Maps from constructor names to codecs.
*/
public static $PATH_SEPARATOR = ".";
/**
* Function: create
*
* Creates the cell path for the given cell. The cell path is a
* concatenation of the indices of all ancestors on the (finite) path to
* the root, eg. "0.0.0.1".
*
* Parameters:
*
* cell - Cell whose path should be returned.
*/
static function create($cell)
{
$result = "";
$parent = $cell->getParent();
while ($parent != null)
{
$index = $parent->getIndex($cell);
$result = $index . mxCellPath::$PATH_SEPARATOR . $result;
$cell = $parent;
$parent = $cell->getParent();
}
return (strlen($result) > 1) ?
substr($result, 0, strlen($result) - 1) : "";
}
/**
* Function: getParentPath
*
* Returns the cell for the specified cell path using the given root as the
* root of the path.
*
* Parameters:
*
* path - Path whose parent path should be returned.
*/
static function getParentPath($path)
{
if ($path != null && strlen($path) > 0)
{
$index = strrpos($path, mxCellPath::$PATH_SEPARATOR);
if ($index === false)
{
return "";
}
else
{
return substr($path, 0, $index);
}
}
return null;
}
/**
* Function: resolve
*
* Returns the cell for the specified cell path using the given root as the
* root of the path.
*
* Parameters:
*
* root - Root cell of the path to be resolved.
* path - String that defines the path.
*/
static function resolve($root, $path)
{
$parent = $root;
$tokens = explode(mxCellPath::$PATH_SEPARATOR, $path);
for ($i=0; $i<sizeof($tokens); $i++)
{
$parent = $parent->getChildAt($tokens[$i]);
}
return $parent;
}
}
?>