-
Notifications
You must be signed in to change notification settings - Fork 1
/
tree.data.cls
72 lines (54 loc) · 2.05 KB
/
tree.data.cls
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
/// Класс с тестовыми данными для отладки работы с деревом
/// с http://jstree.com
Class tree.data Extends (%Persistent, %Populate)
{
/// parent node
Relationship parent As tree.data [ Cardinality = one, Inverse = childs ];
Index parent On parent;
Relationship childs As tree.data [ Cardinality = many, Inverse = parent ];
/// node name
Property name As %String [ Required ];
/// Дополнительные данные для демонстрации работы на стороне браузера
/// Additional data for demo purpose
Property city As %String;
/// Есть ли у узла дочерние?
ClassMethod hasChildren(id As %String) As %Boolean
{
s child="", id=$g(id)
#;&sql(Select ID Into :child From tree.data Where parent=:id)
#;Q (SQLCODE=0)
Q $d(^tree.dataI("parent",id))>0
}
/// Generate data for 3 level tree
ClassMethod init() As %Status
{
d ..%KillExtent()
s parent = ..%New("Belarus",,"")
, sc = parent.%Save()
, pid = parent.%Id()
s node = ..%New("Minskaya",pid,"Minsk")
, sc = node.%Save()
s node = ..%New("Vitebskaya",pid,"Vitebsk")
, sc = node.%Save()
s node = ..%New("Mogilevskaya",pid,"Mogilev")
, sc = node.%Save()
s node = ..%New("Gomelskaya",pid,"Gomel")
, sc = node.%Save()
s node = ..%New("Grodnenskaya", pid, "Grodno")
, sc = node.%Save()
s node = ..%New("Brestskaya", pid, "Brest")
, sc = node.%Save()
Q $$$OK
}
/// This callback method is invoked by the <METHOD>%New</METHOD> method to
/// provide notification that a new instance of an object is being created.
///
/// <P>If this method returns an error then the object will not be created.
/// <p>It is passed the arguments provided in the %New call, there may be up to ten
/// of these arguments, <var>p1, p2, p3, p4, p5, p6, p7, p8, p9, p10</var>
Method %OnNew(name As %String, parent As %String = "", city As %String = "") As %Status [ Private, ProcedureBlock = 1 ]
{
s ..name=$g(name), ..city=$g(city), parent=$g(parent)
d:..%ExistsId(parent) ..parentSetObjectId(parent)
Quit $$$OK
}