-
Notifications
You must be signed in to change notification settings - Fork 4
/
page.i_object.go
189 lines (171 loc) · 4.78 KB
/
page.i_object.go
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package page
import (
"strings"
"github.com/ottemo/commerce/app/models"
"github.com/ottemo/commerce/app/models/cms"
"github.com/ottemo/commerce/db"
"github.com/ottemo/commerce/env"
"github.com/ottemo/commerce/utils"
)
// Get returns object attribute value or nil
func (it *DefaultCMSPage) Get(attribute string) interface{} {
switch strings.ToLower(attribute) {
case "_id", "id":
return it.GetID()
case "enabled":
return it.GetEnabled()
case "identifier":
return it.GetIdentifier()
case "title":
return it.GetTitle()
case "content":
return it.GetContent()
case "created_at":
return it.CreatedAt
case "updated_at":
return it.UpdatedAt
}
return nil
}
// Set sets attribute value to object or returns error
func (it *DefaultCMSPage) Set(attribute string, value interface{}) error {
attribute = strings.ToLower(attribute)
switch attribute {
case "_id", "id":
return it.SetID(utils.InterfaceToString(value))
case "enabled":
return it.SetEnabled(utils.InterfaceToBool(value))
case "identifier":
return it.SetIdentifier(utils.InterfaceToString(value))
case "title":
return it.SetTitle(utils.InterfaceToString(value))
case "content":
return it.SetContent(utils.InterfaceToString(value))
case "created_at":
it.CreatedAt = utils.InterfaceToTime(value)
return nil
case "updated_at":
it.UpdatedAt = utils.InterfaceToTime(value)
return nil
}
return env.ErrorNew(ConstErrorModule, ConstErrorLevel, "e6af9084-fddc-45bf-a90c-9c3d6ff88a57", "unknown attribute '"+attribute+"'")
}
// FromHashMap fills object attributes from map[string]interface{}
func (it *DefaultCMSPage) FromHashMap(input map[string]interface{}) error {
for attribute, value := range input {
if err := it.Set(attribute, value); err != nil {
_ = env.ErrorDispatch(err)
}
}
return nil
}
// ToHashMap represents object as map[string]interface{}
func (it *DefaultCMSPage) ToHashMap() map[string]interface{} {
result := make(map[string]interface{})
result["_id"] = it.GetID()
result["enabled"] = it.Get("enabled")
result["identifier"] = it.Get("identifier")
result["title"] = it.Get("title")
result["content"] = it.Get("content")
result["created_at"] = it.Get("created_at")
result["updated_at"] = it.Get("updated_at")
return result
}
// GetAttributesInfo returns information about object attributes
func (it *DefaultCMSPage) GetAttributesInfo() []models.StructAttributeInfo {
info := []models.StructAttributeInfo{
models.StructAttributeInfo{
Model: cms.ConstModelNameCMSPage,
Collection: ConstCmsPageCollectionName,
Attribute: "_id",
Type: db.ConstTypeID,
IsRequired: false,
IsStatic: true,
Label: "ID",
Group: "General",
Editors: "not_editable",
Options: "",
Default: "",
},
models.StructAttributeInfo{
Model: cms.ConstModelNameCMSPage,
Collection: ConstCmsPageCollectionName,
Attribute: "enabled",
Type: db.ConstTypeBoolean,
IsRequired: true,
IsStatic: true,
Label: "Enabled",
Group: "General",
Editors: "boolean",
Options: "",
Default: "",
},
models.StructAttributeInfo{
Model: cms.ConstModelNameCMSPage,
Collection: ConstCmsPageCollectionName,
Attribute: "identifier",
Type: db.ConstTypeVarchar,
IsRequired: true,
IsStatic: true,
Label: "Identifier",
Group: "General",
Editors: "line_text",
Options: "",
Default: "",
Validators: "",
},
models.StructAttributeInfo{
Model: cms.ConstModelNameCMSPage,
Collection: ConstCmsPageCollectionName,
Attribute: "title",
Type: db.ConstTypeVarchar,
IsRequired: true,
IsStatic: true,
Label: "Title",
Group: "General",
Editors: "line_text",
Options: "",
Default: "",
},
models.StructAttributeInfo{
Model: cms.ConstModelNameCMSPage,
Collection: ConstCmsPageCollectionName,
Attribute: "content",
Type: db.ConstTypeText,
IsRequired: false,
IsStatic: true,
Label: "Content",
Group: "General",
Editors: "html",
Options: "",
Default: "",
},
models.StructAttributeInfo{
Model: cms.ConstModelNameCMSPage,
Collection: ConstCmsPageCollectionName,
Attribute: "created_at",
Type: db.ConstTypeDatetime,
IsRequired: true,
IsStatic: true,
Label: "Created At",
Group: "General",
Editors: "not_editable",
Options: "",
Default: "",
},
models.StructAttributeInfo{
Model: cms.ConstModelNameCMSPage,
Collection: ConstCmsPageCollectionName,
Attribute: "updated_at",
Type: db.ConstTypeDatetime,
IsRequired: true,
IsStatic: true,
Label: "Updated At",
Group: "General",
Editors: "not_editable",
Options: "",
Default: "",
},
}
return info
}