your-land/yl_survey#1 Adds title and description to survey

This commit is contained in:
AliasAlreadyTaken 2024-09-22 16:05:52 +02:00
parent f9664dff5d
commit f78220c7f2
3 changed files with 25 additions and 10 deletions

View File

@ -58,14 +58,16 @@ yl_survey.get_record(s_id)
Returns a table `{survey}` with the values of this UUID or `nil`, if it does not exist
```
yl_survey.create_survey(owner, allow_names, allow_anonymous, allow_changes, timestamp_start, timestamp_end)
yl_survey.create_survey(owner, title, description, allow_names, allow_anonymous, allow_changes, timestamp_start, timestamp_end)
```
Returns `true, s_id` if successful, `false, "errormessage"` if not.
Creates a survey owned by `owner`. `allow_names`, `allow_anonymous`, `allow_changes` are booleans, `timestamp_start` and `timestamp_end` are utc timestamps.
Creates a survey owned by `owner`. `title`, `description` are strings, `allow_names`, `allow_anonymous`, `allow_changes` are booleans, `timestamp_start` and `timestamp_end` are utc timestamps.
* owner: string, required. This is the person who is responsible for this survey
* title: string, optional, defaults to "". This is displayed in every frame of the survey
* description: string, optional, defaults to "". This is displayed on the front page of the survey
* allow_names: boolean, optional, default true. If true, respondents can choose whether to answer with their name recorded. If false, respondents cannot answer with their name recorded.
* allow_anonymous: boolean, optional, default true. If true, respondents can choose whether to answer anonymously. If false, respondents cannot answer anonymously.
* allow_changes: boolean, optional, default false. If true, the respondent may change his answers anytime before the deadline. If false, the answers are fixed once answered.
@ -75,7 +77,7 @@ Creates a survey owned by `owner`. `allow_names`, `allow_anonymous`, `allow_chan
If both allow_names and allow_anonymous are false, then noone can answer this survey. To allow_changes and still allow_anonymous, the playername is hashed. This is no 100% protection against finding out who answered!
```
yl_survey.edit_survey(s_id, owner, allow_names, allow_anonymous, allow_changes, timestamp_start, timestamp_end, delete_responses)
yl_survey.edit_survey(s_id, owner, title, description, allow_names, allow_anonymous, allow_changes, timestamp_start, timestamp_end, delete_responses)
```
Returns `true, s_id, amount_deleted_records` if successful, `false, "errormessage"` if not.

25
api.lua
View File

@ -105,13 +105,14 @@ end
-- yl_survey.create_survey
--
local function create_survey(owner, allow_names, allow_anonymous, allow_changes,
local function create_survey(owner, title, description, allow_names, allow_anonymous, allow_changes,
timestamp_start, timestamp_end)
-- Defense
if ((type(owner) ~= "string") or (owner == "")) then
return false, yl_survey.t("owner must be string")
end
if (title == nil) then title = "" end -- set default
if (description == nil) then description = "" end -- set default
if (allow_names == nil) then allow_names = true end -- set default
if (type(allow_names) ~= "boolean") then
return false, yl_survey.t("allow_names must be boolean")
@ -164,6 +165,8 @@ local function create_survey(owner, allow_names, allow_anonymous, allow_changes,
local metadata = {
id = UUID,
owner = owner,
title = title,
description = description,
allow_names = allow_names,
allow_anonymous = allow_anonymous,
allow_changes = allow_changes,
@ -185,16 +188,16 @@ local function create_survey(owner, allow_names, allow_anonymous, allow_changes,
end
end
function yl_survey.create_survey(owner, allow_names, allow_anonymous,
function yl_survey.create_survey(owner, title, description, allow_names, allow_anonymous,
allow_changes, timestamp_start, timestamp_end)
return create_survey(owner, allow_names, allow_anonymous, allow_changes,
return create_survey(owner, title, description, allow_names, allow_anonymous, allow_changes,
timestamp_start, timestamp_end)
end
-- yl_survey.edit_survey
--
local function edit_survey(id, owner, allow_names, allow_anonymous,
local function edit_survey(id, owner, title, description, allow_names, allow_anonymous,
allow_changes, timestamp_start, timestamp_end,
delete_responses)
-- Defense
@ -204,6 +207,12 @@ local function edit_survey(id, owner, allow_names, allow_anonymous,
if (validate(owner, "string", true) == false) then
return false, yl_survey.t("owner must be string")
end
if (validate(title, "string", true) == false) then
return false, yl_survey.t("title must be string")
end
if (validate(description, "string", true) == false) then
return false, yl_survey.t("description must be string")
end
if (validate(allow_names, "boolean", true) == false) then
return false, yl_survey.t("allow_names must be boolean")
end
@ -243,6 +252,8 @@ local function edit_survey(id, owner, allow_names, allow_anonymous,
local metadata = {
id = record["metadata"].id, -- This value cannot change
owner = owner or record["metadata"].owner,
title = title or record["metadata"].title,
description = description or record["metadata"].description,
allow_names = allow_names or record["metadata"].allow_names,
allow_anonymous = allow_anonymous or record["metadata"].allow_anonymous,
allow_changes = allow_changes or record["metadata"].allow_changes,
@ -271,10 +282,10 @@ local function edit_survey(id, owner, allow_names, allow_anonymous,
end
function yl_survey.edit_survey(id, owner, allow_names, allow_anonymous,
function yl_survey.edit_survey(id, owner, title, description, allow_names, allow_anonymous,
allow_changes, timestamp_start, timestamp_end,
delete_responses)
return edit_survey(id, owner, allow_names, allow_anonymous, allow_changes,
return edit_survey(id, owner, title, description, allow_names, allow_anonymous, allow_changes,
timestamp_start, timestamp_end, delete_responses)
end

View File

@ -35,6 +35,8 @@ This is the planned data structure:
"metadata": {
"id": 0,
"owner": "Alias",
"title" : "My Awesome Survey",
"description" : "The @owner@ would like to know some things until @end_date@.",
"allow_names": true,
"allow_anonymous": true,
"allow_changes": true,