open Util Sql Init
-type poll = {id : int, usr : int, title : string, descr : string, starts : string, ends : string, votes : int}
+type poll = {id : int, usr : int, title : string, descr : string, starts : string, ends : string, votes : int, official : bool}
-fun mkPollRow [id, usr, title, descr, starts, ends, votes] =
+fun mkPollRow [id, usr, title, descr, starts, ends, votes, official] =
{id = C.intFromSql id, usr = C.intFromSql usr, title = C.stringFromSql title,
descr = C.stringFromSql descr, starts = C.stringFromSql starts,
- ends = C.stringFromSql ends, votes = C.intFromSql votes}
+ ends = C.stringFromSql ends, votes = C.intFromSql votes, official = C.boolFromSql official}
| mkPollRow row = Init.rowError ("poll", row)
fun lookupPoll id =
- case C.oneOrNoRows (getDb ()) ($`SELECT id, usr, title, descr, starts, ends, votes
+ case C.oneOrNoRows (getDb ()) ($`SELECT id, usr, title, descr, starts, ends, votes, official
FROM Poll
WHERE id = ^(C.intToSql id)`) of
NONE => raise Fail "Poll not found"
| SOME row => mkPollRow row
fun listPolls () =
- C.map (getDb ()) mkPollRow ($`SELECT id, usr, title, descr, starts, ends, votes
+ C.map (getDb ()) mkPollRow ($`SELECT id, usr, title, descr, starts, ends, votes, official
FROM Poll
ORDER BY ends, starts DESC, title`)
fun listCurrentPolls () =
- C.map (getDb ()) mkPollRow ($`SELECT id, usr, title, descr, starts, ends, votes
+ C.map (getDb ()) mkPollRow ($`SELECT id, usr, title, descr, starts, ends, votes, official
FROM Poll
WHERE EXTRACT(EPOCH FROM starts) <= EXTRACT(EPOCH FROM CURRENT_DATE)
AND EXTRACT(EPOCH FROM ends) >= EXTRACT(EPOCH FROM CURRENT_DATE)
ORDER BY ends, starts DESC, title`)
fun listPollsLimit lim =
- C.map (getDb ()) mkPollRow ($`SELECT id, usr, title, descr, starts, ends, votes
+ C.map (getDb ()) mkPollRow ($`SELECT id, usr, title, descr, starts, ends, votes, official
FROM Poll
ORDER BY starts DESC, ends, title
LIMIT ^(C.intToSql lim)`)
-fun addPoll (usr, title, descr, starts, ends, votes) =
+fun addPoll (usr, title, descr, starts, ends, votes, official) =
let
val db = getDb ()
val id = nextSeq (db, "PollSeq")
in
- C.dml db ($`INSERT INTO Poll (id, usr, title, descr, starts, ends, votes)
+ C.dml db ($`INSERT INTO Poll (id, usr, title, descr, starts, ends, votes, official)
VALUES (^(C.intToSql id), ^(C.intToSql usr), ^(C.stringToSql title), ^(C.stringToSql descr),
- ^(C.stringToSql starts), ^(C.stringToSql ends), ^(C.intToSql votes))`);
+ ^(C.stringToSql starts), ^(C.stringToSql ends), ^(C.intToSql votes), ^(C.boolToSql official))`);
id
end
usr = ^(C.intToSql (#usr poll)), title = ^(C.stringToSql (#title poll)),
descr = ^(C.stringToSql (#descr poll)),
starts = ^(C.stringToSql (#starts poll)), ends = ^(C.stringToSql (#ends poll)),
- votes = ^(C.intToSql (#votes poll))
+ votes = ^(C.intToSql (#votes poll)), official = ^(C.boolToSql (#official poll))
WHERE id = ^(C.intToSql (#id poll))`))
end
AND usr = WebUser.id
ORDER BY name`)
+val votingMembershipRequirement = 45
+
+fun membershipLength id =
+ case C.oneRow (getDb ()) ($`SELECT EXTRACT(DAY FROM (CURRENT_TIMESTAMP - joined))
+ FROM WebUser
+ WHERE id = ^(C.intToSql id)`) of
+ [days] => C.intFromSql days
+ | row => Init.rowError ("membershipLength", row)
+
end