pluginsGLPI / formcreator

GLPI Plugin Formcreator (DOWNLOAD : https://github.com/pluginsGLPI/formcreator/releases)
http://www.teclib-edition.com
GNU General Public License v3.0
174 stars 125 forks source link

Order of My 5 Last Forms (Validator) #2094

Open leecheromerevilit opened 3 years ago

leecheromerevilit commented 3 years ago

Is your feature request related to a problem? Please describe. Currently the order of last 5 forms are DESC, is it possible to customize this by value?

Describe the solution you'd like In mysql, we can specify the order using Order By Field, is this possible in the plugin?

btry commented 3 years ago

Hi

There is no setting for now to customize this quantity.

If someone wants to develop a feature, this should be a new tab in personal settings with a HTML input (ordropdown ?) to choose the limit.

In the version 2.11 or later you can customize by editing a default value in some methods. It will apply for everyone as an hardcoded value.

https://github.com/pluginsGLPI/formcreator/blob/develop/inc/form.class.php#L1076

leecheromerevilit commented 3 years ago

Hi

In the function getMyLastAnswersAsValidator on formanswer.class.php, is there any way I can use similar MySQL query "ORDER BY FIELD" to hardcode the desired sorting order using formanswer status?

This code works on DB from the SQL generated on DEBUG mode.

ORDER BY FIELD(glpi_plugin_formcreator_formanswers.status, "101", "103", "102", "100")

Regards,

btry commented 3 years ago

Hi

As far as I know, the query builder in GLPI does not support this syntax. You can use a QueryExpression object (provided by GLPI Core)

Something like the following should work. Replace the ORDER key in the array with this (I did not tested it:

'ORDER' => new QueryExpression("FIELD ($formAnswerTable.status, '101', '103', '102', 100')"),

You may read the unit tests of GLPI 9.5 to see if there is an example for this specific syntax, and read glpi/inc/dbmysqliterator.class.php method handleOrderClause() .

leecheromerevilit commented 3 years ago

Hi

Thanks for a detailed response. I will surely provide my feedback after I get it to work.