Package org.ametys.plugins.survey.dao
Class SurveyDAO
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.plugins.survey.dao.AbstractDAO
org.ametys.plugins.survey.dao.SurveyDAO
- All Implemented Interfaces:
LogEnabled
,Component
,Contextualizable
,Serviceable
DAO for manipulating surveys.
-
Field Summary
Modifier and TypeFieldDescriptionprotected PageDAO
The page DAOprotected SiteConfigurationExtensionPoint
The site configuration.protected SurveyAnswerDao
The survey answer dao.static final String
The Avalon roleFields inherited from class org.ametys.plugins.survey.dao.AbstractDAO
_cocoonContext, _context, _currentUserProvider, _jsonUtils, _observationManager, _resolver, _siteManager, _uploadManager
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncopySurvey
(String surveyId, String label, String title) Copies and pastes a survey.createStatsMap
(Survey survey) Create the statistics Map for a survey.Creates a survey.deleteSurvey
(String id) Deletes a survey.protected void
dispatchChoiceStats
(SurveySession session, Map<String, Map<String, Object>> questionStats, Map<String, Set<String>> valueMap) Dispatch stats on a choice question.protected void
dispatchMatrixStats
(SurveySession session, Map<String, Map<String, Object>> questionStats, Map<String, Set<String>> valueMap) Dispatch stats on a matrix question.protected void
dispatchStats
(Survey survey, Collection<SurveySession> sessions, Map<String, Map<String, Map<String, Object>>> stats) Dispatch the survey user sessions (input) in the statistics map.protected void
dispatchTextStats
(SurveySession session, Map<String, Map<String, Object>> questionStats, Map<String, Set<String>> valueMap) Dispatch stats on a text question.Edits a survey.getChildren
(String id) Gets the children pages of a surveyprotected String
getChoiceLabel
(SurveyQuestion question, String choiceId) Get an option label, depending on the question type.protected String
getMailBody
(String surveyId, String message, String siteName) Get the email bodyprotected String
Get the email subjectprotected String
getOptionLabel
(SurveyQuestion question, String optionId) Get an option label, depending on the question type.protected Survey
Get the survey containing the given object.getStatistics
(String id) Generates statistics on each question of a survey.Gets properties of a surveyGets properties of a surveyprotected String
getSurveyUri
(String surveyId, String siteName) Get the survey page urigetSurveyZoneItems
(String siteName, String lang, String surveyId) Get all zone items which contains the surveygetValueMap
(SurveyQuestion question, String value) Get the user-input value as a Map from the database value, which is a single serialized string.protected boolean
hasAlreadyAnswered
(String surveyId, UserIdentity user) Determines if the user has already answered to the surveyGets the online status of a surveyboolean
Determines if the survey is privatemoveObject
(String id, String oldParent, String newParent, long index) Moves an element of the survey.reinitSurvey
(String id, boolean invalidate) Reinitializes a survey.removeExistingServices
(String siteName, String lang, String surveyId) Remove the existing services if existssendInvitations
(String surveyId, String message, String siteName) Sends invitations emails.void
service
(ServiceManager serviceManager) setRedirection
(String surveyId, String pageId) Sets a new redirection page to the survey.Transforms the statistics map into an array with some info.validateSurvey
(String id) Validates a survey.Methods inherited from class org.ametys.plugins.survey.dao.AbstractDAO
_getCurrentUser, contextualize, getPictureInfo, getSurveyRootNode, setPicture, updateReferencesAfterCopy, updateReferencesAfterCopy, updateReferencesAfterCopy
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
ROLE
The Avalon role -
_surveyAnswerDao
The survey answer dao. -
_pageDAO
The page DAO -
_siteConfiguration
The site configuration.
-
-
Constructor Details
-
SurveyDAO
public SurveyDAO()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Overrides:
service
in classAbstractDAO
- Throws:
ServiceException
-
getSurvey
Gets properties of a survey- Parameters:
id
- The id of the survey- Returns:
- The properties
-
getSurvey
Gets properties of a survey- Parameters:
survey
- The survey- Returns:
- The properties
-
isPrivate
Determines if the survey is private- Parameters:
survey
- The survey- Returns:
- true if the survey is reading restricted
-
isOnline
Gets the online status of a survey- Parameters:
id
- The id of the survey- Returns:
- A map indicating if the survey is valid and if it is online
-
getChildren
Gets the children pages of a survey- Parameters:
id
- The id of the survey- Returns:
- A map of pages properties
-
createSurvey
public Map<String,String> createSurvey(Map<String, Object> values, String siteName, String language) throws ExceptionCreates a survey.- Parameters:
values
- The survey valuessiteName
- The site namelanguage
- The language- Returns:
- The id of the created survey
- Throws:
Exception
- if an error occurs during the survey creation process
-
editSurvey
Edits a survey.- Parameters:
values
- The survey valuessiteName
- The site namelanguage
- The language- Returns:
- The id of the edited survey
-
copySurvey
Copies and pastes a survey.- Parameters:
surveyId
- The id of the survey to copylabel
- The labeltitle
- The title- Returns:
- The id of the created survey
- Throws:
Exception
- if an error occurs during the survey copying process
-
deleteSurvey
Deletes a survey.- Parameters:
id
- The id of the survey to delete- Returns:
- The id of the deleted survey
-
validateSurvey
Validates a survey.- Parameters:
id
- The id of the survey to validate- Returns:
- The id of the validated survey
-
reinitSurvey
Reinitializes a survey.- Parameters:
id
- The id of the survey to validateinvalidate
- True to invalidate the survey- Returns:
- The id of the reinitialized survey
-
setRedirection
Sets a new redirection page to the survey.- Parameters:
surveyId
- The id of the survey to edit.pageId
- The id of the redirection page.- Returns:
- The id of the edited survey
-
moveObject
public Map<String,String> moveObject(String id, String oldParent, String newParent, long index) throws Exception Moves an element of the survey.- Parameters:
id
- The id of the element to move.oldParent
- The id of the element's parent.newParent
- The id of the new element's parent.index
- The index where to move. null to place the element at the end.- Returns:
- A map with the ids of the element, the old parent and the new parent
- Throws:
Exception
- if an error occurs when moving an element of the survey
-
sendInvitations
Sends invitations emails.- Parameters:
surveyId
- The id of the survey.message
- The message content.siteName
- The site name.- Returns:
- An empty map
-
getStatistics
Generates statistics on each question of a survey.- Parameters:
id
- The survey id- Returns:
- A map containing the statistics
-
removeExistingServices
Remove the existing services if exists- Parameters:
siteName
- The site namelang
- The languagesurveyId
- The id of survey- Returns:
- The list of modified pages ids
-
getSurveyZoneItems
public AmetysObjectIterable<ModifiableZoneItem> getSurveyZoneItems(String siteName, String lang, String surveyId) Get all zone items which contains the survey- Parameters:
siteName
- the site namelang
- the languagesurveyId
- the survey id- Returns:
- the zone items
-
getParentSurvey
Get the survey containing the given object.- Parameters:
obj
- the object.- Returns:
- the parent Survey.
-
createStatsMap
Create the statistics Map for a survey.- Parameters:
survey
- the survey.- Returns:
- the statistics Map. It is of the following form: questionId -> optionId ->choiceId -> count.
-
dispatchStats
protected void dispatchStats(Survey survey, Collection<SurveySession> sessions, Map<String, Map<String, Map<String, Object>>> stats) Dispatch the survey user sessions (input) in the statistics map.- Parameters:
survey
- the survey.sessions
- the user sessions.stats
- the statistics Map to fill.
-
dispatchTextStats
protected void dispatchTextStats(SurveySession session, Map<String, Map<String, Object>> questionStats, Map<String, Set<String>> valueMap) Dispatch stats on a text question.- Parameters:
session
- the survey session.questionStats
- the Map to fill with the stats.valueMap
- the value map.
-
dispatchChoiceStats
protected void dispatchChoiceStats(SurveySession session, Map<String, Map<String, Object>> questionStats, Map<String, Set<String>> valueMap) Dispatch stats on a choice question.- Parameters:
session
- the survey session.questionStats
- the Map to fill with the stats.valueMap
- the value map.
-
dispatchMatrixStats
protected void dispatchMatrixStats(SurveySession session, Map<String, Map<String, Object>> questionStats, Map<String, Set<String>> valueMap) Dispatch stats on a matrix question.- Parameters:
session
- the survey session.questionStats
- the Map to fill with the stats.valueMap
- the value map.
-
statsToArray
protected List<Map<String,Object>> statsToArray(Survey survey, Map<String, Map<String, Map<String, Object>>> stats) Transforms the statistics map into an array with some info.- Parameters:
survey
- The surveystats
- The filled statistics Map.- Returns:
- A list of statistics.
-
getOptionLabel
Get an option label, depending on the question type.- Parameters:
question
- the question.optionId
- the option ID.- Returns:
- the question label, can be the empty string.
-
getChoiceLabel
Get an option label, depending on the question type.- Parameters:
question
- the question.choiceId
- the choice id.- Returns:
- the option label, can be the empty string.
-
getValueMap
Get the user-input value as a Map from the database value, which is a single serialized string.- Parameters:
question
- the question.value
- the value from the database.- Returns:
- the value as a Map.
-
hasAlreadyAnswered
Determines if the user has already answered to the survey- Parameters:
surveyId
- The survey iduser
- the user- Returns:
true
if the user has already answered
-
getMailSubject
Get the email subject- Returns:
- The subject
-
getMailBody
Get the email body- Parameters:
surveyId
- The survey idmessage
- The messagesiteName
- The site name- Returns:
- The text body
-
getSurveyUri
Get the survey page uri- Parameters:
surveyId
- The survey idsiteName
- The site name- Returns:
- The survey absolute uri
-