2024-06-12 22:24:00 +02:00
|
|
|
(in-package :ml-survey)
|
|
|
|
|
|
|
|
(defun make-surveys-db-file ()
|
|
|
|
(make-db-file "surveys-db.lisp"))
|
|
|
|
|
2024-06-11 18:27:17 +02:00
|
|
|
(defclass survey ()
|
|
|
|
((id :initarg :id :reader survey-id)
|
|
|
|
(data-dir :initarg :data-dir :reader survey-data-dir)
|
|
|
|
(properties :initarg :properties :reader survey-properties)))
|
|
|
|
|
|
|
|
(defmethod initialize-instance :after ((survey survey) &key)
|
|
|
|
(with-slots (id data-dir properties) survey
|
|
|
|
(setf data-dir (uiop:merge-pathnames*
|
|
|
|
(format nil "~a/" id)
|
|
|
|
(ensure-data-dir)))
|
|
|
|
(setf properties (first (rest (assoc (parse-integer id)
|
|
|
|
(load-response (make-surveys-db-file))))))))
|
|
|
|
|
|
|
|
(defgeneric survey-id-p (survey)
|
|
|
|
(:documentation "Check if the survey ID is present in the surveys database."))
|
|
|
|
|
|
|
|
(defgeneric survey-data-dir-files (survey)
|
|
|
|
(:documentation "Get the list of files in the survey's data directory."))
|
|
|
|
|
|
|
|
(defgeneric survey-data-dir-p (survey)
|
|
|
|
(:documentation "Check if the survey's data directory exists."))
|
|
|
|
|
|
|
|
(defmethod survey-id-p ((survey survey))
|
|
|
|
(let ((ids (mapcar #'car (load-response (make-surveys-db-file)))))
|
|
|
|
(if (member (parse-integer (survey-id survey)) ids) t nil)))
|
|
|
|
|
|
|
|
(defmethod survey-data-dir-files ((survey survey))
|
|
|
|
(uiop:directory-files (survey-data-dir survey)))
|
|
|
|
|
|
|
|
(defmethod survey-data-dir-p ((survey survey))
|
|
|
|
(uiop:directory-exists-p (survey-data-dir survey)))
|
|
|
|
|
2024-06-23 13:23:14 +02:00
|
|
|
(defmethod survey-properties-title ((survey survey))
|
|
|
|
(cdr (assoc "title" (survey-properties survey) :test #'string-equal)))
|
|
|
|
|
|
|
|
(defmethod survey-properties-description ((survey survey))
|
|
|
|
(cdr (assoc "description" (survey-properties survey) :test #'string-equal)))
|
|
|
|
|
2024-06-11 18:27:17 +02:00
|
|
|
(defun build-questionnaire-link (survey-id resource)
|
|
|
|
(format nil "/survey/~a/questionnaire~a" survey-id resource))
|
|
|
|
|
|
|
|
(defmethod survey-html ((survey survey))
|
|
|
|
(spinneret:with-html
|
2024-06-14 17:47:54 +02:00
|
|
|
(:dl (loop for property in (survey-properties survey)
|
|
|
|
for key = (car property)
|
|
|
|
for value = (cdr property) do
|
|
|
|
(:dt key)
|
|
|
|
(cond ((string= key "questionnaire")
|
2024-06-20 23:29:47 +02:00
|
|
|
(:dd (:a :href (build-questionnaire-link (survey-id survey) value)
|
|
|
|
(format nil "Open Questionnaire ~a" value))))
|
2024-06-14 17:47:54 +02:00
|
|
|
(t (:dd value)))))))
|