コード例 #1
0
 /**
  * @param ISurveyQuestionTemplate $question
  * @return bool
  */
 public function belongsTo(ISurveyQuestionTemplate $question)
 {
     foreach ($this->getQuestions() as $q) {
         if ($q->getIdentifier() === $question->getIdentifier()) {
             return true;
         }
     }
     return false;
 }
 /**
  * @param ISurveyStep $current_step
  * @param ISurveyQuestionTemplate $question
  * @param ISurveyAnswer $answer
  * @return FormField
  */
 public function build(ISurveyStep $current_step, ISurveyQuestionTemplate $question, ISurveyAnswer $answer)
 {
     $value = null;
     if (!is_null($answer)) {
         $value = $answer->value();
     }
     $field = new SurveyOrganizationField($question, $value);
     if ($question->isMandatory()) {
         $field->setRequired();
     }
     return $field;
 }
コード例 #3
0
 /**
  * @param ISurveyStep $current_step
  * @param ISurveyQuestionTemplate $question
  * @param ISurveyAnswer $answer
  * @return FormField
  */
 public function build(ISurveyStep $current_step, ISurveyQuestionTemplate $question, ISurveyAnswer $answer)
 {
     $options = array();
     if ($question->IsCountrySelector) {
         $extra_options = array('Worldwide' => 'Worldwide', 'Prefer not to say' => 'Prefer not to say', 'Too many to list' => 'Too many to list');
         $options = array_merge($extra_options, CountryCodes::$iso_3166_countryCodes);
     } else {
         foreach ($question->Values()->sort('Order') as $val) {
             $options[$val->ID] = empty($val->Label) ? $val->Value : $val->Label;
         }
     }
     $default_value = $question->DefaultValue();
     $field = $question->IsMultiSelect ? new MultiDropdownField($question->name(), $question->label(), $options) : new DropdownField($question->name(), $question->label(), $options);
     if ($question->isReadOnly()) {
         $field->setDisabled(true);
     }
     if ($question->isMandatory()) {
         $field->setAttribute('data-rule-required', 'true');
         $field->setAttribute('aria-required', 'true');
     }
     if ($default_value) {
         $field->setValue($default_value->ID);
     }
     if (!is_null($answer)) {
         $field->setValue($answer->value());
     }
     $empty_string = $question->EmptyString;
     if (!empty($empty_string)) {
         if ($question->UseChosenPlugin && $question->IsMultiSelect) {
             $field->setAttribute('data-placeholder', $empty_string);
         } else {
             $field->setEmptyString($empty_string);
         }
     }
     $this->buildDependantRules($current_step, $question, $field);
     if ($question->UseChosenPlugin) {
         $field->addExtraClass('chosen');
         if (count($question->DependsOn()) === 0) {
             $field->addExtraClass('chosen-visible');
         }
         Requirements::customScript("jQuery(document).ready(function(\$){\n                            var form    = \$('.survey_step_form');\n                            var form_id = form.attr('id');\n                            \$('#'+form_id+'_{$question->name()}').chosen({width: '30%'});\n                        });\n                    ");
     }
     return $field;
 }
コード例 #4
0
 /**
  * @param ISurveyQuestionTemplate $question
  * @param mixed $answer_value
  * @return ISurveyAnswer
  */
 public function buildAnswer(ISurveyQuestionTemplate $question, $answer_value)
 {
     $answer = new SurveyAnswer();
     if (is_array($answer_value)) {
         $answer_value = str_replace('{comma}', ',', $answer_value);
         $answer->Value = implode(',', $answer_value);
     } else {
         $answer->Value = $answer_value;
     }
     $answer->QuestionID = $question->getIdentifier();
     return $answer;
 }
 /**
  * @param ISurveyStep $current_step
  * @param ISurveyQuestionTemplate $question
  * @param ISurveyAnswer $answer
  * @return FormField
  */
 public function build(ISurveyStep $current_step, ISurveyQuestionTemplate $question, ISurveyAnswer $answer)
 {
     $field = new SurveyRadioButtonMatrixField($question->name(), $question->label(), $question);
     if (!is_null($answer)) {
         $field->setAnswer($answer);
     }
     if ($question->isReadOnly()) {
         $field->setDisabled(true);
     }
     if ($question->isMandatory()) {
         $field->setValidationAttribute('data-rule-radio_button_matrix_required', $field->name);
         $field->setValidationAttribute('data-msg-radio_button_matrix_required', sprintf('you must select at least one item (%s)', $question->name()));
     }
     $this->buildDependantRules($current_step, $question, $field);
     return $field;
 }
 /**
  * @param ISurveyStep $current_step
  * @param ISurveyQuestionTemplate $question
  * @param ISurveyAnswer $answer
  * @return FormField
  */
 public function build(ISurveyStep $current_step, ISurveyQuestionTemplate $question, ISurveyAnswer $answer)
 {
     $field = new TextField($question->name(), $question->label());
     $field->setValue($question->initialValue());
     if ($question->isReadOnly()) {
         $field->setDisabled(true);
     }
     if ($question->isMandatory()) {
         $field->setAttribute('data-rule-required', 'true');
     }
     if (!is_null($answer)) {
         $field->setValue($answer->value());
     }
     $this->buildDependantRules($current_step, $question, $field);
     return $field;
 }
 /**
  * @param ISurveyStep $current_step
  * @param ISurveyQuestionTemplate $question
  * @param ISurveyAnswer $answer
  * @return FormField
  */
 public function build(ISurveyStep $current_step, ISurveyQuestionTemplate $question, ISurveyAnswer $answer)
 {
     $options = array();
     foreach ($question->Values()->sort('Order') as $val) {
         $options[$val->ID] = empty($val->Label) ? $val->Value : $val->Label;
     }
     $field = new SurveyRankingField($question->name(), $question->label(), $options, $value = '', $form = null, $emptyString = null, $question);
     if ($question->isReadOnly()) {
         $field->setDisabled(true);
     }
     if ($question->isMandatory()) {
         $field->setValidationAttribute('data-rule-ranking_required', $field->ID());
         $field->setValidationAttribute('data-msg-ranking_required', sprintf('you must select at least one item (%s)', $question->name()));
     }
     if (!is_null($answer)) {
         $field->setValue($answer->value());
     }
     $this->buildDependantRules($current_step, $question, $field);
     return $field;
 }
 /**
  * @param ISurveyStep $current_step
  * @param ISurveyQuestionTemplate $question
  * @param ISurveyAnswer $answer
  * @return FormField
  */
 public function build(ISurveyStep $current_step, ISurveyQuestionTemplate $question, ISurveyAnswer $answer)
 {
     $options = array();
     foreach ($question->Values()->sort('Order') as $val) {
         $options[$val->ID] = empty($val->Label) ? $val->Value : $val->Label;
     }
     $field = new SurveyCheckboxSetField($question->name(), $question->label(), $options, $value = '', $form = null, $emptyString = null, $question);
     if ($question->isReadOnly()) {
         $field->setDisabled(true);
     }
     if ($question->isMandatory()) {
         $field->setRequired();
     }
     if (!is_null($answer)) {
         $field->setValue($answer->value());
     }
     $this->buildDependantRules($current_step, $question, $field);
     return $field;
 }
 /**
  * @param ISurveyStep $current_step
  * @param ISurveyQuestionTemplate $question
  * @param ISurveyAnswer $answer
  * @return FormField
  */
 public function build(ISurveyStep $current_step, ISurveyQuestionTemplate $question, ISurveyAnswer $answer)
 {
     $options = array();
     foreach ($question->Values()->sort('Order') as $val) {
         $options[$val->ID] = empty($val->Label) ? $val->Value : $val->Label;
     }
     $field = new OptionSetField($question->name(), $question->label(), $options);
     $default_value = $question->getDefaultValue();
     if (!is_null($default_value) && $default_value->ID > 0) {
         $field->setValue($default_value->ID);
     }
     if ($question->isReadOnly()) {
         $field->setDisabled(true);
     }
     if ($question->isMandatory()) {
         $field->setAttribute('data-rule-required', 'true');
     }
     if (!is_null($answer)) {
         $field->setValue($answer->value());
     }
     $this->buildDependantRules($current_step, $question, $field);
     return $field;
 }
コード例 #10
0
ファイル: Survey.php プロジェクト: Thingee/openstack-org
 /**
  * @param ISurveyQuestionTemplate $question
  * @return ISurveyAnswer
  */
 public function findAnswerByQuestion(ISurveyQuestionTemplate $question)
 {
     foreach ($this->getSteps() as $step) {
         if ($step instanceof SurveyRegularStep) {
             $answer = $step->getAnswerByTemplateId($question->getIdentifier());
             if (!is_null($answer)) {
                 return $answer;
             }
         }
     }
     return null;
 }
 /**
  * @param ISurveyStep $current_step
  * @param ISurveyQuestionTemplate $question
  * @param ISurveyAnswer $answer
  * @return FormField
  */
 public function build(ISurveyStep $current_step, ISurveyQuestionTemplate $question, ISurveyAnswer $answer)
 {
     $field = new LiteralField($question->name(), $question->Content);
     return $field;
 }
 /**
  * @param ISurveyStep $current_step
  * @param ISurveyQuestionTemplate $question
  * @param array $js_rules
  * @param FormField $field
  */
 public function apply(ISurveyStep $current_step, ISurveyQuestionTemplate $question, array $js_rules, FormField $field)
 {
     if (count($js_rules)) {
         $js = "jQuery(document).ready(function(\$){\n\n                    var form                = \$('.survey_step_form');\n                    var form_id             = form.attr('id');\n                    var clickable_fields    = [];\n                    var selectable_fields   = [];\n                    var rankable_fields     = [];\n                    var double_table_fields = [];\n                    ";
         //hide and set js rule
         $field->addExtraClass('hidden');
         $question_id = $question->name();
         foreach ($js_rules as $id => $info) {
             $d = $info['question'];
             $values = $info['values'];
             $operator = $info['operator'];
             $visibility = $info['visibility'];
             if ($d instanceof ISurveyClickableQuestion || $d instanceof ISurveyRankableQuestion || $d instanceof IDoubleEntryTableQuestionTemplate) {
                 foreach ($values as $value) {
                     $option_id = $d->name();
                     if ($d instanceof ISurveyClickableQuestion) {
                         if ($d instanceof IMultiValueQuestionTemplate && intval($value) > 0) {
                             //$value = $d->getValueById(intval($d->ValueID));
                             $option_id .= '_' . str_replace(' ', '', intval($value));
                         }
                         $js .= " clickable_fields.push(\$('#'+form_id+'_{$option_id}'));";
                     }
                     if ($d instanceof ISurveyRankableQuestion) {
                         if ($d instanceof IMultiValueQuestionTemplate && intval($value) > 0) {
                             if ($d instanceof IMultiValueQuestionTemplate && intval($value) > 0) {
                                 //$value = $d->getValueById(intval($d->ValueID));
                                 $option_id .= '_' . str_replace(' ', '', intval($value));
                             }
                             $js .= " rankable_fields.push( \$('#'+form_id+'_{$option_id}') );";
                         }
                     }
                     if ($d instanceof IDoubleEntryTableQuestionTemplate) {
                         $js .= " double_table_fields.push({table : \$('#'+'{$option_id}'), value: {$value} });";
                     }
                 }
             }
             if ($d instanceof ISurveySelectableQuestion && $d instanceof IMultiValueQuestionTemplate) {
                 $option_id = $d->name();
                 $values = implode(',', $values);
                 $js .= " selectable_fields.push({ddl : \$('#'+form_id+'_{$option_id}'), values: [{$values}] });";
             }
         }
         $js .= "for(var i = 0 ; i < selectable_fields.length; i++ ){\n                form.survey_validation_rules('addRequiredAnswer4SelectAbleGroup', selectable_fields, \$('#{$question_id}'));\n                }";
         $js .= "if(clickable_fields.length > 0 )\n                form.survey_validation_rules('addRequiredAnswer4CheckAbleGroup', clickable_fields, \$('#{$question_id}') ); ";
         $js .= "if(rankable_fields.length > 0 )\n                form.survey_validation_rules('addRequiredAnswer4RankAbleGroup', rankable_fields, \$('#{$question_id}') );";
         $js .= "if(double_table_fields.length > 0 )\n                form.survey_validation_rules('addRequiredAnswer4TableGroup', double_table_fields, \$('#{$question_id}') );\n                });";
         Requirements::customScript($js);
     }
 }