-
Notifications
You must be signed in to change notification settings - Fork 0
/
Data.php
241 lines (226 loc) · 9.22 KB
/
Data.php
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php
use Base\Data as BaseData;
/**
* Skeleton subclass for representing a row from the '_data' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class Data extends BaseData
{
/**
* creates history values for reference fields
*
* @return void
* @author Urs Hofer
*/
function getHistory()
{
$thisfield = $this->getTemplates();
$contribution = $this->getContributions();
$settings = json_decode($thisfield->getConfigSys(), true);
$retval = [];
if ($settings['fromfield'])
$field = \TemplatesQuery::create()->findPk($settings['fromfield']);
else
$field = $thisfield;
if ($settings['fromtemplate'])
$template = \TemplatenamesQuery::create()->findPk($settings['fromtemplate']);
else
$template = $thisfield->getTemplatenames();
if ($settings['fromissue'])
$issue = \IssuesQuery::create()->findPk($settings['fromissue']);
else
$issue = $contribution->getIssues();
if ($settings['frombook'])
$book = \BooksQuery::create()->findPk($settings['frombook']);
else
$book = $contribution->getIssues()->getBooks();
if ($settings['fromchapter'])
$chapter = \FormatsQuery::create()->findPk($settings['fromchapter']);
else
$chapter = $contribution->getFormats();
if (!$chapter || !$book || !$issue || !$template || !$field) {
array_push($retval, ["id"=>-1,"value"=>"Error - adjust template settings"]);
}
else {
switch ($settings['history_command']) {
//
// BOOK HISTORY
// needs : -
// option : -
// Returns books
//
case 'books':
foreach(\BooksQuery::create() as $_b) {
array_push($retval, ["id"=>$_b->getId(),"value"=>$_b->getName()]);
}
break;
//
// ISSUES HISTORY
// option : frombook(string), otherwise self
// option : restrict_to_open(bool)
// Returns issues of a book
//
case 'issues':
$issues = \IssuesQuery::create()->_if($settings['restrict_to_book'])
->filterByBooks($book)
->_endif()
->_if($settings['restrict_to_open'])
->filterByStatus('open')
->_endif();
foreach($issues as $_b) {
array_push($retval, ["id"=>$_b->getId(),"value"=>$_b->getName()]);
}
break;
//
// CHAPTERS HISTORY
// option : frombook(string), otherwise self
// Returns chapters of a book
//
case 'chapters':
$formats = \FormatsQuery::create()->_if($settings['restrict_to_book'])
->filterByBooks($book)
->_endif();
foreach($formats as $_b) {
array_push($retval, ["id"=>$_b->getId(),"value"=>$_b->getName()]);
}
break;
//
// CLOUD HISTORY
// TODO
// Returns cloud matrix data for a field.
//
case 'cloud':
array_push($retval, ["id"=>-1,"value"=>"not yet implemented"]);
//
// OTHER HISTORY
// option: restrict_to_issue(bool): true = fromissue or self / false = all issues
// option: restrict_to_open(bool): true = open contributions / false = all contributions
// option: fromfield (necessary for other history)
// Returns chapters of a book
//
case 'other':
$_data = \DataQuery::create()->filterByTemplates($field)
->_if($settings['restrict_to_issue'])
->useContributionsQuery()
->filterByIssues($issue)
->endUse()
->_endif()
->useContributionsQuery()
->_if($settings['restrict_to_open'])
->filterByStatus('Open')
->_else()
->filterByStatus('Open')
->_or()
->filterByStatus('Close')
->_endif()
->endUse();
foreach($_data as $_b) {
array_push($retval, ["id"=>$_b->getId(),"value"=>$_b->getContent()]);
}
break;
//
// SELF HISTORY
// option: restrict_to_issue(bool): true = fromissue or self / false = all issues
// option: restrict_to_open(bool): true = open contributions / false = all contributions
// option: fromfield (necessary for other history)
// Returns chapters of a book
//
case 'self':
$_data = \DataQuery::create()->filterByTemplates($field)
->_if($settings['restrict_to_issue'])
->useContributionsQuery()
->filterByIssues($issue)
->endUse()
->_endif()
->useContributionsQuery()
->_if($settings['restrict_to_open'])
->filterByStatus('Open')
->_else()
->filterByStatus('Open')
->_or()
->filterByStatus('Close')
->_endif()
->endUse();
foreach($_data as $_b) {
foreach(json_decode($_b->getContent(), true) as $_d) {
$retval[$_d] = ["id"=>$_d,"value"=>$_d];
}
}
ksort($retval);
break;
//
// CONTRIBUTIONS HISTORY
// option: restrict_to_issue(bool): true = fromissue or self / false = all issues
// option: restrict_to_open(bool): true = open contributions / false = all contributions
// option: restrict_to_chapter(bool): true = fromchapter or self / false = all chapters
// option: fromtemplate(string), otherwise self
// Returns contributions of a issue
//
case 'contributional':
$_data = \ContributionsQuery::create()->_if($settings['restrict_to_issue'])
->filterByIssues($issue)
->_endif()
->_if($settings['restrict_to_open'])
->filterByStatus('Open')
->_else()
->filterByStatus('Open')
->_or()
->filterByStatus('Close')
->_endif()
->_if($settings['restrict_to_chapter'])
->filterByFormats($chapter)
->_endif()
->_if($settings['restrict_to_template'])
->filterByTemplatenames($template)
->_endif();
foreach($_data as $_b) {
array_push($retval, ["id"=>$_b->getId(),"value"=>$_b->getName()]);
}
break;
//
// STRUCTURAL HISTORY
// option: fromtemplate(string), otherwise fields of own template
// Returns fields of a template
//
case 'structural':
foreach(\TemplatesQuery::create()->filterByTemplatenames($template) as $_t) {
array_push($retval, ["id"=>$_t->getId(),"value"=>$_t->getFieldname()]);
}
# code...
break;
//
// FIXED HISTORY
// needs : fixedvalues(array of strings)
// option : -
// Returns fixed string values
//
case 'fixed':
foreach ($settings['fixedvalues'] as $key => $value) {
array_push($retval, ["id"=>$key,"value"=>$value]);
}
break;
}
// Always add a disabled state
array_push($retval, ["id"=>-1,"value"=>"* Disabled *"]);
}
return $retval;
}
/**
* decodes the content from json
* it the result is not an array, it will be created
*
* @return void
* @author Urs Hofer
*/
function getDataAlwaysAsArray()
{
$data = json_decode($this->getContent(), true);
return (!is_array($data)?[$data]:$data);
}
}