Wiki source code of Datenbankzähler-Plugin


Show last authors
1 [[**Plugin download**>>url:https://customer.formcycle.eu/index.php/apps/files/?dir=/FORMCYCLE%20-%20Plugins%20Customer/fc-plugin-bundle-dbcounter&fileid=5521||target="_blank"]] (requires login)
2
3 {{content/}}
4
5 {{figure image="plugin_dbcounter_workflow_select_en.png" width="600"}}
6 The database counter plugin may be installed as either a client plugin or a system plugin. It requires no additional configuration. Once installed, it offers to new workflow actions: //Variable// and //Counter.//. The //Counter// action requires you to choose a fixed counter that you would like to change. In contrast, the //Variable// action lets you choose the counter based on the submitted form data.
7 {{/figure}}
8
9 The database counter plugin lets you create one or more counter in a database. It also adds a new menu entry to the backend where you can view and edit all available counters. You can then use the [[workflow>>doc:Formcycle.Designer.Workflow.WebHome]] to increment or decrement the counter. This plugin is subject to additional charge.
10
11 Some of the possible use cases include:
12
13 * A registration form for a weekly event, when you need to keep track of the number of registered participants. You can then block new registrations for a certain date when the maximum number of participants has been reached.
14 * Generating a unique {{smallcaps}}id{{/smallcaps}} for a form record that is independent of internal {{smallcaps}}id{{/smallcaps}}s used by {{formcycle/}}. Useful especially when the {{smallcaps}}id{{/smallcaps}} needs to conform to a certain pattern or needs to be reset in fixed intervals.
15 * Running the [[actions>>doc:Formcycle.Designer.Workflow.Actions.WebHome]] of a certain [[state>>doc:Formcycle.Designer.Workflow.States]] n-times, where //n// is determined by the value of a submitted form field.
16
17 Once the plugin is installed, you can manage the available counter in a separate backend page. You can check which counters exist currently and add or delete counter. The current value of each counter is displayed as well, and if necessary, you can also change the counter's value.
18
19 In addition, this plugin offers two new [[workflow>>doc:Formcycle.Designer.Workflow.WebHome]] [[actions>>doc:Formcycle.Designer.Workflow.Actions.WebHome]]: //Counter// and //Variable//. The action //Counter// requires you to select a predefined counter. The action //Variable//, on the other hand, lets you select a counter based on the value of a submitted fo m field. See the sections on each action below for further details.
20
21 Lastly, you can also access the current value of a counter either via a [[variable>>doc:Formcycle.UserInterface.Variables]] during workflow processing or [[via an {{smallcaps}}Ajax{{/smallcaps}} request from within an opened form>>doc:Formcycle.Designer.Form.CodingPanel.ScriptTab.WebHome]].
22
23 Each counter has got both a name as well as a unique [[{{smallcaps}}Uuid{{/smallcaps}}>>https://de.wikipedia.org/wiki/Universally_Unique_Identifier]]. The {{smallcaps}}Uuid{{/smallcaps}} uniquely identifies a counter and is used, for example, when querying the counter's current value via an {{smallcaps}}Ajax{{/smallcaps}} request.
24
25 This is plugin bundle that includes two workflow action plugins, one placeholder replacer plugin, and one servlet action plugin. The following sections describe these plugins in more detail.
26
27 == Menu entry "Counter configuration" ==
28
29 {{info}}
30 This plugin adds a new [[role permission>>doc:Formcycle.UserInterface.UserSettings.Roles]] that controls whether a user is granted access to this menu entry. Contact your administrator in case you do not see the menu entry and believe you should have access.
31 {{/info}}
32
33 {{figure image="plugin_dbcounter_config_base_en.png" width="600"}}
34 The menu with an overview of all existing counter. You can add or delete counter, or modify existing counters.
35 {{/figure}}
36
37 Once installed, a new menu entry appears in the main menu bar to the left. Please note that you may have to sign out and sign in again. The menu //Counter configuration// contains an overview of all existing counters, including their name and their current value. You can modify or delete existing counter, or add new counters.
38
39 Press the plus icon to the top left to add a new counter. If you would like to delete an existing counter, click on that counter to select it, then press the trash icon to the top left.
40
41 === Properties ===
42
43 Select a counter by clicking on it in the list of counters to the left. The following details are shown for the counter:
44
45 ; {{smallcaps}}Uuid{{/smallcaps}}
46 : A unique {{smallcaps}}id{{/smallcaps}} of the counter. You need to use this {{smallcaps}}Uuid{{/smallcaps}}, for example, when you want to retrieve the counter's current value via an {{smallcaps}}Ajax{{/smallcaps}} request, see also the servlet action plugin below.
47 ; Current value
48 : The current value of the counter.
49 ; Creation date
50 : The date when the counter was created.
51 ; Last change
52 : The date of the most recent change to the counter's value.
53
54 Additionally, you can also edit the following properties of a counter:
55
56 ; Counter name
57 : The name of this counter. When you change the name of a counter, you may have to change existing //Variable// action, placeholders and {{smallcaps}}Ajax{{/smallcaps}} requests that reference a counter by its name. {{smallcaps}}Ajax{{/smallcaps}} requests that reference a counter by its {{smallcaps}}Uuid{{/smallcaps}} do not have to be updated.
58 ; Description
59 : An optional description of this counter. This description is shown only within this backend menu.
60 ; Initial value
61 : The initial value of this counter. This is also the value that is used when a workflow action resets a counter to its initial value.
62 ; Reset automatically
63 : When this option es enabled, the value of this counter is reset in period intervals.
64
65 === Reset automatically ===
66
67 The following settings are available when the option to reset the counter automatically is enabled:
68
69 {{info}}
70 When a counter is reset, then after the counter action was processed, the counter's value will be equal to the configured initial value. For example: Assume the counter action was configured to increment the counter by //3// each time it is executed, and should be reset daily. Let the the current counter value be //37// and the intial value //11//. The first counter action that is executed on a new day will now reset the counter to //11//, and not be incremented at all. Starting with the second counter action of that day, the counter will be incremented by //3// each time the action is executed.
71 {{/info}}
72
73 {{info}}
74 Please note that the counter is not reset by background task, but only when the workflow action //Counter// or //Variable// is executed. Or, to be more precise, the counter value is reset (instead of being incremented or decremented), when the time points at which the counter should have been reset contains at least one point that lies between the last point in time the counter value was modified and the current point in time.
75 {{/info}}
76
77 ; Condition
78 : Lets you choose when and how the counter should be reset. The following options are available:
79 :; Counter greater than or equal
80 :: Available only when the counting action was set to //count up//. The counter is reset to its initial value when, after the counter was incremented, its value is now greater than or equal to the given limit.
81 :; Counter less than or equal
82 :: Available only when the counting action was set to //count down//. The counter is reset to its initial value when, after the counter was decremented, its value is now less than or equal to the given limit.
83 :; daily
84 :: The counter is reset each day at the given time of day.
85 :; weekly
86 :: The counter is reset at each of the given days of the week and at the given time of the day.
87 :; monthly
88 :: The counter is reset each month at the given date and time of the day.
89 :; yearly
90 :: The counter is reset each year the given day, month and time of the day.
91
92 == Workflow action "Counter" ==
93
94 {{figure image="plugin_dbcounter_action_counter_en.png"}}
95 The settings for the workflow action //Counter//. You can select the counter to modify and how its value should be changed, e.g. incrementing or decrementing it by a certain amount.
96 {{/figure}}
97
98 Once the plugin is installed, you can select the new action //Counter// in the [[workflow>>doc:Formcycle.Designer.Workflow.WebHome]]. This action lets you modify the value of a predefined counter.
99
100 Compared with the action //Variable//, here you need to select a predefined counter. You should have created this counter in the counter configuration menu (see above). Use this action when you need a global, non-dynamic counter, such as when you want to generate an identifier for each form record.
101
102 ; Counter name
103 : Name of the counter to be modified. For each counter you can see its name as well as its {{smallcaps}}Uuid{{/smallcaps}}. The {{smallcaps}}Uuid{{/smallcaps}} uniquely identifies a counter and is used when querying it via an {{smallcaps}}Ajax{{/smallcaps}} request. To delete a counter, first select the counter, then click on the thrash icon to the right. To add a counter, first click on the plus icon, then enter a name for the new counter, and finally save the counter by pressing the floppy disc icon.
104 ; Counting action
105 : Lets you chose how the value of the counter should be changed. Possible options are:
106 :; Increment count
107 :: Adds the given amount to the current value of the counter.
108 :; Decrement count
109 :: Substracts the given amount from the current value of the counter.
110 :; Reset counter to start value
111 :: Sets the current value of the counter back to the selected initial value.
112 ; Step size
113 : Amount by which the counter is incremented or decremented.
114 ; Use global settings (deprecated)
115 : You should leave this option checked and configure the counter settings in the counter configuration menu (see above). It exists only to ensure backwards compatibility with older versions of the plugin and may be removed in future versions.
116
117 == Workflow action "Variable" ==
118
119 {{figure image="plugin_dbcounter_action_variable_en.png"}}
120 Settings for the workflow action //Variable//. It lets you select a counter dynamically by its name. You can also make use of placeholder variables to select a counter based on the value of some form field.
121 {{/figure}}
122
123 Once the plugin is installed, you can select the new action //Variiable// in the [[workflow>>doc:Formcycle.Designer.Workflow.WebHome]]. This action lets you select a counter by its name and modify its value.
124
125 Compared with the action //Counter//, here you do not have to choose a predefined counter. You can also use [[placeholder variables>>doc:Formcycle.UserInterface.Variables]] to select a counter based on the submitted form data. In case the counter does not exists yet, a new counter is created dynamically.
126
127 Use this action when you need different counters for each submitted form record. For example, if you have got a participation form where users can sign up for a certain date, you can use a counter for each date to keep track of the number of registered people for that date. The counter name could be formatted like //participants-year-month-day//.
128
129 === Change variable ===
130
131 Select the name of the variable ("counter") to modify and how its value should be changed.
132
133 ; Counter name
134 : Name of the counter to modify. Enter name of the counter, not its {{smallcaps}}Uuid{{/smallcaps}}). You can also use [[placeholder variables>>doc:Formcycle.UserInterface.Variables]] to select a counter based on a submitted form field.
135 ; Counting action
136 : Lets you chose how the value of the counter should be changed. Possible options are:
137 :; Increment count
138 :: Adds the given amount to the current value of the counter.
139 :; Decrement count
140 :: Subtracts the given amount from the current value of the counter.
141 :; Reset counter to start value
142 :: Sets the current value of the counter back to the selected initial value.
143 ; Step size
144 : Amount by which the counter is incremented or decremented.
145
146 === Default settings if variable does not exists yet ===
147
148 In case the variable ("counter") with the given name does not exist yet, a new counter is created. Here you can edit the default settings for a newly created counter. In case the counter exists already, these settings do not have any effect.
149
150 ; Initial value
151 : The initial value of the newly created counter.
152 ; Reset automatically
153 : Whether the newly created counter should be reset automatically. When this option is enabled, a few more settings appear. See the section on the counter configuration menu above for further details.
154
155 == General return parameters ==
156
157 {{figure image="plugin_dbcounter_action_return_parameters_en.png"}}
158 Settings for the return parameters of the counter action. You can access the returned values via placeholder variables.
159 {{/figure}}
160
161 Sometimes it may be necessary to access the new value of the counter. To do so, you can use [[action variables>>doc:Formcycle.UserInterface.Variables]] for accessing the returned values of an action. The section //general return parameters// lets you configure the key you need to use for accessing the return values. For example, assume a counter action were named //CountUp//. Then you can use the variable //[%$CountUp.RESULT[0].currentValue%]// to access the current counter value, provided you entered the key //currentValue// in the input field for the //Counter// return value. The following return values are available:
162
163 ; 1 - ResultCode
164 : A numerical value that indicates whether the counter action was successful or not. The following result codes are possible:
165 :; 1 (OK)
166 :: The counter action was processed successfully.
167 :; 10 (UNKNOWN_ACTION_ERROR)
168 :: The counter action could not be processed, an unknown counting action was selected. The currently supported counting actions are //count up//, //count down// and //reset counter to start value//.
169 :; 11 (PARSING_ERROR)
170 :: A settings does not conform to the expected data type or syntax; such as when a letter was entered for the initial value (instead of a number).
171 :; 40 (INTERNAL_ERROR)
172 :: The counter action was not successful. The type of error cannot be specified more closely.
173 ; 2 - ResultMessage
174 : An English description of the result (success or error).
175 ; 3 - Counter
176 : The new numerical value of the counter, after the counting action was applied.
177 ; 4 - IsReset
178 : Either //true//, when the counter was reset during the current action; or //false// if it was not reset.
179 ; 5 - CounterAfterReset
180 : In case the counter was reset: The numerical value of the counter before the reset.
181
182 == System variable plugin ==
183
184 {{figure image="dbcounter-plugin-placeholder_en.png"}}
185 An example for how to retrieve the current value of a counter. Here we read a counter that is used for keeping track of the number of participants of some event. We then check whether the value exceeds the maximum number of participants. Based on the result of this check, we can display an appropriate error message to the user in case the limit was reached. By performing this check during workflow processing, we can validate the data on the server and prevent manipulatios. Please note that it is best practice to give the user some feedback while the fill out the form and inform the user in case no more free slots are available.
186 {{/figure}}
187
188 Once the plugin is installed, you can access the current value of the plugin with a [[system variable>>doc:Formcycle.UserInterface.Variables]]. This can be used, for example, to access the counter value in the condition of a workflow action and compare it with a submitted value. The system variable has got the following pattern:
189
190 {{code language="none"}}
191 [%$DBCOUNTER.<CounterName>%]
192 {{/code}}
193
194 For example, in order to access the value of a counter named //test//, you can use the following variable:
195
196 {{code language="none"}}
197 [%$DBCOUNTER.test%]
198 {{/code}}
199
200 In case you need to access a counter that may not exist yet, you need to provide an initial value for the counter. When the counter does not exist yet, a new counter with the given initial value is created. Use the following pattern:
201
202 {{code language="none"}}
203 [%$DBCOUNTER(<CounterName>, <InitialValue>)%]
204 {{/code}}
205
206 For example, if the counter is named //participants-2020-03-17// and should start at //0// in case it does not exist, you can use the following variable:
207
208 {{code language="none"}}
209 [%$DBCOUNTER(participants-2020-03-17, 0)%]
210 {{/code}}
211
212 == Servlet action plugin ==
213
214 {{figure image="dbcounter_plugin_servlet_action.png"}}
215 An example for how the counter value can be accessed via an {{smallcaps}}Ajax{{/smallcaps}} request. The {{smallcaps}}Url{{/smallcaps}} is build with the metadata available in the form context. This avoids having to enter the {{smallcaps}}Url{{/smallcaps}} directly in the code, which is prone to error: the host or context path could change, for example, when the form is moved between a development and production.
216 {{/figure}}
217
218
219 Once the plugin is installed, a new servlet plugin action is available that lets you access the current value of a counter via an {{smallcaps}}Http{{/smallcaps}} request. This is useful, for example, when you would like to read the counter's current value from within a form and display it in the form. The {{smallcaps}}Url{{/smallcaps}} for the counter action plugin servlet takes the following pattern:
220
221 {{code language="none"}}
222 https://<Host>/<FormcycleContextPath>/plugin?name=Servlet%20Counter&client-id=<ClientId>&id=<CounterUuid>
223 {{/code}}
224
225 Assuming {{formcycle/}} was installed locally and runs in the context path //formcycle//, and the counter plugins was installed within a client with the {{smallcaps}}id{{/smallcaps}} //1//, and the {{smallcaps}}Uuid{{/smallcaps}} of the counter is //bc49d3b0-f869-4e59-864e-ddcc2925ed63//, the {{smallcaps}}Url{{/smallcaps}} is:
226
227 {{code language="none"}}
228 https://localhost:8080/formcycle/plugin?name=Servlet%20Counter&client-id=1&id=bc49d3b0-f869-4e59-864e-ddcc2925ed63
229 {{/code}}
230
231 Alternatively, you can also use the {{smallcaps}}id{{/smallcaps}} of the form instead of the //client-id//. Both the client and the form {{smallcaps}}id{{/smallcaps}} are used only to identify the servlet to be executed; and are not used in any way by this counter servlet.
232
233 {{code language="none"}}
234 https://<Host>/<FormcycleContextPath>/plugin?name=Servlet%20Counter&project-id=<FormID>&id=<CounterUuid>
235 {{/code}}
236
237 === HTTP parameter ===
238
239 In addtional to the parameters mentioned above, you can also specify a few more paramters as {{smallcaps}}Url{{/smallcaps}} parameters. The following is an overview of all available parameters.
240
241 ; name
242 : The name of the servlet plugin action to execute. Set this to //Servlet Counter// for this plugin.
243 ; client-id
244 : {{smallcaps}}id{{/smallcaps}} of the client where the counter plugin was installed. Not required in case the plugin was installed as a system plugin. Only one of //client-id// or //project-id// may be specified.
245 ; project-id
246 : {{smallcaps}}id{{/smallcaps}} of a form that belongs to a client that has access to the counter plugin., in dem das Zähler-Plugin zur Verfügung steht. Only one of //client-id// or //project-id// may be specified.
247 ; id
248 : {{smallcaps}}Uuid{{/smallcaps}} of counter to read. In case a counter with the given {{smallcaps}}Uuid{{/smallcaps}} does not exist yet, a corresponding error code is returned, see below. Only one of //id// or //counter-name// may be specified.
249 ; counter-name
250 : Name of the counter to read. In case a counter with the given name does not exist yet, a new counter is created with the given initial value.Only one of //id// or //counter-name// may be specified.
251 ; counter-initial
252 : Optional. The initial value of the counter, in case it does not exist yet. Defaults to //0//. This parameter is allowed only when //counter-name// is specified.
253 ; counter-array
254 : Optional. Either //true// or //false//, defaults to //false//. When this is set to //true//, the parameter //counter-name// or //id// may be specified multiple times. This will return an array with the current value of all specified counters. This can be used, for example, to reduce the amount of {{smallcaps}}Http{{/smallcaps}} requests when you need to query multiple counter simultaneously.
255
256 === HTTP response ===
257
258 If the servlet action plugin is executed successfully, it returns a {{smallcaps}}Json{{/smallcaps}} object as shown in the figure to the right. When the parameter //counter-array// was set to //true//, a {{smallcaps}}Json{{/smallcaps}} array is returned instead, with each item being a {{smallcaps}}Json{{/smallcaps}} object as described below.
259
260 The {{smallcaps}}Json{{/smallcaps}}-Objekt has got the following properties:
261
262 ; Status
263 : Indicates whether the servlet request was successful. The value is another {{smallcaps}}Json{{/smallcaps}} object with the following entries:
264 :; Msg
265 :: A numerical value that indicates whether the servlet request was successful. Possible values are:
266 ::; 0 (OK)
267 ::: The request was successful.
268 ::; 12 (NO_REQUEST_ID_ERROR)
269 ::: The request did not specify a counter UUID.
270 ::; 13 (NO_COUNTER_TO_UUID_ERROR)
271 ::: No counter with the specified UUID exists.
272 ::; 40 (INTERNAL_ERROR)
273 ::: The counter action was not successful. The type of error cannot be specified more closely.
274 :; Code
275 :: An English description of the result (success or error).
276 ; Counter
277 : Details about the requested counter. The value is another {{smallcaps}}Json{{/smallcaps}} object with the following entries:
278 :; LastChange
279 :: The date and time of the most recent modification of the counter value. The date and time is formatted according to the current server locale.
280 :; LastChangeTimestamp
281 :: The date and time of the most recent modification of the counter value. The timestamp is a whole number indicating the number of milliseconds January 1st, 1970, 00:00:00 GMT.
282 :; Value
283 :: The current numerical value of the counter.
284 :; UUID
285 :: The UUID of the requested counter.
286 :; Name
287 :: The name of the requested counter.
288
289 == Changelog ==
290
291 This section lists all known versions of this plugin and describes the changes that were made in each version.
292
293 === 2.3.3 ===
294
295 * Fixed some spelling mistakes
296
297 === 2.3.2 ===
298
299 * Fixed a UI bug: The checkbox //Use global settings// (action //Counter//) now toggles the options below correctly.
300 * Fixed some spelling mistakes
301
302 === 2.3.1 ===
303
304 * Fixed a bug with {{smallcaps}}Mysql{{/smallcaps}} that prevented this plugin from working with that database management system.
305
306 === 2.3.0 ===
307
308 * New action: //Variable//
309 * Lets you select a counter by its name and allows for placeholder variables. This requires an initial value.
310 * New placeholder variable: //DBCOUNTER(name, initialValue)//. Creates a new counter in case a counter with the given name does not exist yet.
311 * Added 3 new parameters to the servlet action plugin: //counter-name//, //counter-initial// and //counter-array//.
312
313 === 2.2.0 ===
314
315 * Make sure to reset the counter even when its value is only read
316 * Portal page that adds a new menu entry to the backend: Counter configuration
317 * Deprecate editing a counter's settings in the workflow action directly
318
319 === 2.1.0 ===
320
321 * Modifications for {{formcycle/}} version 6.1.6
322 * The //CounterPlugin// and //ServletCounterPlugin// had the same name, this resulted in errors
323 * Fixed an error that resulted in a counter not being resetted correctly
324 * Add a new property to the {{smallcaps}}Json{{/smallcaps}} object returned by the servlet action plugin: //Counter.LastChangeTimestamp//
325 * Added a new system variable replacer plugin that lets you access the value of a counter via a variable: //[%DBCOUNTER.name%]//
326
327 === 2.0.0 ===
328
329 * Modifications to make the plugin work with {{formcycle/}} version 6.0.2
330
331 === 1.0.1 ===
332
333 * Fix a bug where the counter value was not set when retrieved for the first time
334
335 === 1.0.0 ===
336
337 * Initial version