Exemplo n.º 1
0
  /**
   * Checks if a unique question UID is shown according to the values of the given survey
   *
   * @param uid
   * @param id_survey
   * @return
   */
  public static boolean isHiddenQuestionByUidAndSurvey(String uid, Long id_survey) {
    // get question by uid
    Question question = getQuestionByUid(uid);
    if (question == null) return false;

    Long id_question = question.getId_question();
    long hasParentOptionActivated =
        new Select()
            .count()
            .from(Value.class)
            .as("v")
            .join(QuestionOption.class, Join.JoinType.LEFT)
            .as("qo")
            .on(
                Condition.column(ColumnAlias.columnWithTable("v", Value$Table.ID_QUESTION))
                    .eq(ColumnAlias.columnWithTable("qo", QuestionOption$Table.ID_QUESTION)),
                Condition.column(ColumnAlias.columnWithTable("v", Value$Table.ID_OPTION))
                    .eq(ColumnAlias.columnWithTable("qo", QuestionOption$Table.ID_OPTION)))
            .join(Match.class, Join.JoinType.LEFT)
            .as("m")
            .on(
                Condition.column(ColumnAlias.columnWithTable("qo", QuestionOption$Table.ID_MATCH))
                    .eq(ColumnAlias.columnWithTable("m", Match$Table.ID_MATCH)))
            .join(QuestionRelation.class, Join.JoinType.LEFT)
            .as("qr")
            .on(
                Condition.column(ColumnAlias.columnWithTable("m", Match$Table.ID_QUESTION_RELATION))
                    .eq(
                        ColumnAlias.columnWithTable(
                            "qr", QuestionRelation$Table.ID_QUESTION_RELATION)))
            // Parent child relationship
            .where(
                Condition.column(
                        ColumnAlias.columnWithTable("qr", QuestionRelation$Table.OPERATION))
                    .eq(1))
            // For the given survey
            .and(
                Condition.column(ColumnAlias.columnWithTable("v", Value$Table.ID_SURVEY))
                    .eq(id_survey))
            // The child question in the relationship is 'this'
            .and(
                Condition.column(
                        ColumnAlias.columnWithTable("qr", QuestionRelation$Table.ID_QUESTION))
                    .eq(id_question))
            .count();
    return hasParentOptionActivated > 0 ? false : true;
  }
Exemplo n.º 2
0
 public void setQuestion(Question question) {
   this.question = question;
   this.id_parent = (question != null) ? question.getId_question() : null;
 }