Fixes allowed_answers wrong check. Thankyou tour

This commit is contained in:
AliasAlreadyTaken 2024-09-17 11:49:07 +02:00
parent 1a41313613
commit 01380c7622
2 changed files with 23 additions and 7 deletions

12
api.lua
View File

@ -312,8 +312,8 @@ local function create_question(id, question, category, sort, allowed_types,
-- Specialcase : answers cannot be nil or empty if allowedtypes has either multiplechoice or singlechoice
if (((answers == nil) or (next(answers) == nil)) and
((allowed_types["multiplechoice"] ~= nil) or
(allowed_types["singlechoice"] ~= nil))) then
((yl_survey.table_contains(allowed_types, "multiplechoice") == true) or
(yl_survey.table_contains(allowed_types, "singlechoice") == true))) then
return false, yl_survey.t(
"answers cannot be nil or empty if allowedtypes has either multiplechoice or singlechoice")
end
@ -415,8 +415,8 @@ local function edit_question(id, q_id, question, sort, category, allowed_types,
-- Specialcase : answers cannot be nil or empty if allowedtypes has either multiplechoice or singlechoice
if ((answers ~= nil) and (next(answers) ~= nil) and
((allowed_types["multiplechoice"] ~= nil) or
(allowed_types["singlechoice"] ~= nil))) then
((yl_survey.table_contains(allowed_types, "multiplechoice") == true) or
(yl_survey.table_contains(allowed_types, "singlechoice") == true))) then
return false, yl_survey.t(
"answers cannot be nil or empty if allowedtypes has either multiplechoice or singlechoice")
end
@ -446,9 +446,7 @@ local function edit_question(id, q_id, question, sort, category, allowed_types,
local no = 0
local n_responses = t_question["responses"] or {}
if (delete_responses == true) then
for _,_ in pairs(n_responses) do
no = no + 1
end
for _, _ in pairs(n_responses) do no = no + 1 end
n_responses = {}
end

View File

@ -30,6 +30,24 @@ end
function yl_survey.priv_exists(priv) return priv_exists(priv) end
-- table.contains
local function table_contains(t, m)
if ((type(m) ~= "number") and (type(m) ~= "string") and (type(m) ~= "boolean")) then
return nil, yl_survey.t("member must be primitive")
end
for _, v in pairs(t) do
if (v == m) then
return true
end
end
return false
end
function yl_survey.table_contains(t, m)
return table_contains(t, m)
end
-- Hash name
local function hash_name(name)