343 lines
10 KiB
Plaintext
Executable File
343 lines
10 KiB
Plaintext
Executable File
//
|
|
// Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
|
|
//
|
|
// This library is free software; you can redistribute it and/or
|
|
// modify it under the terms of the GNU Lesser General Public License
|
|
// as published by the Free Software Foundation; either version 2.1 of
|
|
// the License, or (at your option) any later version.
|
|
//
|
|
// This library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
// Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
// License along with this library; if not, write to the Free Software
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
//
|
|
// $Id: Survey.pdl 287 2005-02-22 00:29:02Z sskracic $
|
|
// $DateTime: 2004/08/17 23:26:27 $
|
|
model com.arsdigita.simplesurvey;
|
|
|
|
import com.arsdigita.kernel.*;
|
|
import com.arsdigita.formbuilder.*;
|
|
|
|
object type Survey extends ACSObject {
|
|
component FormSection[1..1] formSection = join ss_surveys.form_id
|
|
to bebop_form_sections.form_section_id;
|
|
PackageInstance[1..1] packageInstance = join ss_surveys.package_id
|
|
to apm_packages.package_id;
|
|
Date[0..1] startDate = ss_surveys.start_date DATE;
|
|
Date[0..1] endDate = ss_surveys.end_date DATE;
|
|
String[0..1] quizType = ss_surveys.quiz_type VARCHAR(50);
|
|
Boolean[0..1] responsesPublic = ss_surveys.responses_public_p CHAR(1);
|
|
reference key (ss_surveys.survey_id);
|
|
|
|
}
|
|
|
|
query GetAnswersForResponse {
|
|
BigDecimal answerID;
|
|
String attributeString;
|
|
String answerValue;
|
|
|
|
do {
|
|
select ss_answers.answer_id,
|
|
ss_answers.response_id,
|
|
ss_answers.value,
|
|
bebop_components.attribute_string
|
|
from ss_answers, bebop_components
|
|
where ss_answers.response_id = :responseID
|
|
and ss_answers.label_id = bebop_components.component_id
|
|
order by ss_answers.response_id, ss_answers.answer_id
|
|
} map {
|
|
answerID = ss_answers.answer_id;
|
|
attributeString = bebop_components.attribute_string;
|
|
answerValue = ss_answers.value;
|
|
}
|
|
}
|
|
|
|
|
|
query GetFormLabels {
|
|
BigDecimal labelID;
|
|
String attributeString;
|
|
|
|
do {
|
|
select bebop_components.component_id,
|
|
bebop_components.attribute_string
|
|
from bebop_component_hierarchy, acs_objects, bebop_components, ss_surveys
|
|
where bebop_component_hierarchy.container_id = ss_surveys.form_id
|
|
and ss_surveys.survey_id = :surveyID
|
|
and bebop_component_hierarchy.component_id =
|
|
acs_objects.object_id
|
|
and acs_objects.default_domain_class = 'com.arsdigita.formbuilder.WidgetLabel'
|
|
and bebop_components.component_id = bebop_component_hierarchy.component_id
|
|
order by bebop_components.component_id
|
|
} map {
|
|
labelID = bebop_components.component_id;
|
|
attributeString = bebop_components.attribute_string;
|
|
}
|
|
}
|
|
|
|
query GetAnswersToQuestion {
|
|
BigDecimal answerID;
|
|
String answerValue;
|
|
|
|
do {
|
|
select ss_answers.answer_id,
|
|
ss_answers.value
|
|
from ss_answers, ss_responses
|
|
where ss_answers.response_id = ss_responses.response_id
|
|
and ss_answers.label_id = :labelID
|
|
and ss_responses.entry_date > :startDate
|
|
and ss_responses.entry_date < :endDate
|
|
|
|
} map {
|
|
answerID = ss_answers.answer_id;
|
|
answerValue = ss_answers.value;
|
|
}
|
|
}
|
|
|
|
query getCorrectAnswerToQuestion {
|
|
// This returns one correct answer value corresponding to the question's label
|
|
String answerValue;
|
|
do {
|
|
select value from ss_correct_answers
|
|
where label_id = :labelID
|
|
} map {
|
|
answerValue = value;
|
|
}
|
|
}
|
|
|
|
query getCorrectAnswers {
|
|
// This returns all labels to one survey
|
|
String answerValue;
|
|
BigInteger widgetID;
|
|
String parameterName;
|
|
String parameterModel;
|
|
String domainClass;
|
|
|
|
do {
|
|
select sca.value,
|
|
bc.component_id as widget_id,
|
|
bw.parameter_name,
|
|
bw.parameter_model,
|
|
o.default_domain_class
|
|
from bebop_component_hierarchy bch,
|
|
bebop_components bc,
|
|
bebop_widgets bw,
|
|
ss_surveys s,
|
|
ss_correct_answers sca,
|
|
acs_objects o
|
|
where bch.container_id = s.form_id
|
|
and sca.widget_id = bch.component_id
|
|
and bc.component_id = bch.component_id
|
|
and bc.component_id = bw.widget_id
|
|
and bc.component_id = o.object_id
|
|
and s.survey_id = :surveyID
|
|
} map {
|
|
widgetID = widget_id;
|
|
answerValue = sca.value;
|
|
parameterName = bw.parameter_name;
|
|
parameterModel = bw.parameter_model;
|
|
domainClass = o.default_domain_class;
|
|
}
|
|
}
|
|
|
|
query correctAnswerExists {
|
|
Boolean answerExists;
|
|
do {
|
|
select 1 as answer_exists_p from ss_correct_answers
|
|
where label_id = :labelID and widget_id = :widgetID
|
|
} map {
|
|
answerExists = answer_exists_p;
|
|
}
|
|
}
|
|
data operation insertCorrectAnswer {
|
|
do {
|
|
insert into ss_correct_answers( label_id, widget_id, value )
|
|
values ( :labelID, :widgetID, :value )
|
|
}
|
|
}
|
|
data operation updateCorrectAnswer {
|
|
do {
|
|
update ss_correct_answers set value = :value
|
|
where label_id = :labelID and widget_id = :widgetID
|
|
}
|
|
}
|
|
|
|
data operation updateAnswerValue {
|
|
do {
|
|
update bebop_options set answer_value = :answerValue
|
|
where option_id = :optionID
|
|
}
|
|
}
|
|
query GetAllAnswers {
|
|
BigDecimal responseID;
|
|
BigDecimal labelID;
|
|
String answerValue;
|
|
|
|
do {
|
|
select ss_answers.value,
|
|
ss_answers.response_id,
|
|
ss_answers.label_id
|
|
from ss_answers
|
|
where ss_answers.response_id in (select response_id from ss_responses
|
|
where survey_id = :surveyID)
|
|
order by ss_answers.response_id, ss_answers.label_id
|
|
} map {
|
|
answerValue = ss_answers.value;
|
|
responseID = ss_answers.response_id;
|
|
labelID = ss_answers.label_id;
|
|
}
|
|
}
|
|
|
|
query GetWidgetClassAfterLabel {
|
|
String widgetClass;
|
|
|
|
do {
|
|
select acs_objects.default_domain_class
|
|
from bebop_component_hierarchy, acs_objects
|
|
where bebop_component_hierarchy.component_id = acs_objects.object_id
|
|
and bebop_component_hierarchy.container_id = (select container_id from bebop_component_hierarchy
|
|
where component_id = :labelID)
|
|
and bebop_component_hierarchy.order_number = (select order_number + 1 from
|
|
bebop_component_hierarchy where component_id = :labelID)
|
|
} map {
|
|
widgetClass = acs_objects.default_domain_class;
|
|
}
|
|
}
|
|
|
|
query GetOneAnswerQuestionStatistics {
|
|
String value;
|
|
BigDecimal numberOfAnswers;
|
|
|
|
do {
|
|
select count(ss_answers.answer_id) number_of_answers,
|
|
ss_answers.value
|
|
from ss_answers
|
|
where ss_answers.label_id = :labelID
|
|
group by ss_answers.value
|
|
} map {
|
|
value = ss_answers.value;
|
|
numberOfAnswers = number_of_answers;
|
|
}
|
|
}
|
|
|
|
query getAnswerOption {
|
|
String questionText;
|
|
String answerText;
|
|
BigDecimal answerValue;
|
|
BigDecimal optionID;
|
|
|
|
do {
|
|
select h2.component_id as option_id,
|
|
op.label as answer_text,
|
|
op.answer_value,
|
|
bc.attribute_string as question_text
|
|
from bebop_component_hierarchy h1,
|
|
bebop_component_hierarchy h2,
|
|
bebop_component_hierarchy h3,
|
|
bebop_components bc,
|
|
bebop_options op,
|
|
acs_objects o2
|
|
where h2.container_id = h1.component_id
|
|
and h2.component_id = op.option_id
|
|
and bc.component_id = h3.component_id
|
|
and o2.object_id = h3.component_id
|
|
and h3.order_number = h1.order_number - 1
|
|
and h3.container_id = h1.container_id
|
|
and h2.component_id = op.option_id
|
|
and op.option_id = :optionID
|
|
and o2.default_domain_class = 'com.arsdigita.formbuilder.WidgetLabel'
|
|
} map {
|
|
optionID = option_id;
|
|
answerValue = answer_value;
|
|
questionText = question_text;
|
|
answerText = answer_text;
|
|
}
|
|
}
|
|
query getSurveyStatistics {
|
|
BigDecimal score;
|
|
BigDecimal surveyNumber;
|
|
BigDecimal surveyPercentage;
|
|
|
|
do {
|
|
select score,
|
|
survey_number,
|
|
round((survey_number/total)*100) as survey_percentage
|
|
from ( select r1.score,
|
|
count(*) survey_number,
|
|
r2.total
|
|
from ss_responses r1,
|
|
(select count(*) as total from ss_responses r3
|
|
where r3.survey_id = :surveyID) r2
|
|
where r1.survey_id = :surveyID
|
|
group by r1.score, r2.total) s
|
|
} map {
|
|
surveyNumber = survey_number;
|
|
score = score;
|
|
surveyPercentage = survey_percentage;
|
|
}
|
|
}
|
|
|
|
query GetTotalNumberOfAnswers {
|
|
BigDecimal numberOfAnswers;
|
|
|
|
do {
|
|
select count(*) number_of_answers
|
|
from ss_answers where label_id = :labelID
|
|
} map {
|
|
numberOfAnswers = number_of_answers;
|
|
}
|
|
}
|
|
|
|
query getAnswerOptions {
|
|
// Returns all singleselect/select multiple questions with one row per possible answer
|
|
// for the selected survey. Yes, we are assuming that the label is always directly before the widget on the form.
|
|
String questionText;
|
|
String answerText;
|
|
BigDecimal optionID;
|
|
BigDecimal labelID;
|
|
BigDecimal widgetID;
|
|
BigDecimal answerValue;
|
|
do {
|
|
select h1.component_id as widget_id,
|
|
h2.component_id as option_id,
|
|
bc.attribute_string as label_text,
|
|
bc.component_id as label_id,
|
|
op.label as option_text,
|
|
op.answer_value
|
|
from bebop_component_hierarchy h1,
|
|
bebop_component_hierarchy h2,
|
|
bebop_component_hierarchy h3,
|
|
bebop_options op,
|
|
bebop_components bc,
|
|
ss_surveys s,
|
|
acs_objects o2
|
|
where h2.container_id = h1.component_id
|
|
and h1.container_id = s.form_id
|
|
and bc.component_id = h3.component_id
|
|
and o2.object_id = h3.component_id
|
|
and h2.component_id = op.option_id
|
|
and h3.order_number = h1.order_number - 1
|
|
and h3.container_id = h1.container_id
|
|
and o2.default_domain_class = 'com.arsdigita.formbuilder.WidgetLabel' and s.survey_id = :surveyID
|
|
order by widget_id
|
|
} map {
|
|
widgetID = widget_id;
|
|
optionID = option_id;
|
|
questionText = label_text;
|
|
answerText = option_text;
|
|
labelID = label_id;
|
|
answerValue = answer_value;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|