app/controllers/response_controller.rb
# This method should be moved to survey_deployment_contoller.rb
This method should be moved to survey_deployment_contoller.rb
This method should be moved to survey_deployment_contoller . rb
def pending_surveys
    unless session[:user] 
      redirect_to '/'
      return
    end
    course_participants = CourseParticipant.where(user_id: session[:user].id)
    assignment_participants = AssignmentParticipant.where(user_id: session[:user].id)
    @surveys = []
    if course_participants
      course_participants.each do |cp|
        survey_deployments = CourseSurveyDeployment.where(parent_id: cp.parent_id)
        if survey_deployments
          survey_deployments.each do |survey_deployment|
            if survey_deployment && Time.now > survey_deployment.start_date && Time.now < survey_deployment.end_date
              @surveys << 
              [
                'survey' => Questionnaire.find(survey_deployment.questionnaire_id), 
                'survey_deployment_id' => survey_deployment.id, 
                'start_date' => survey_deployment.start_date, 
                'end_date' => survey_deployment.end_date,
                'parent_id' => cp.parent_id, 
                'participant_id' => cp.id,
                'global_survey_id' => survey_deployment.global_survey_id
              ]
            end
          end
        end
      end
    end
    if assignment_participants
      assignment_participants.each do |ap|
        survey_deployments = AssignmentSurveyDeployment.where(parent_id: ap.parent_id)
        if survey_deployments
          survey_deployments.each do |survey_deployment|
            if survey_deployment && Time.now > survey_deployment.start_date && Time.now < survey_deployment.end_date
              @surveys << 
              [
                'survey' => Questionnaire.find(survey_deployment.questionnaire_id), 
                'survey_deployment_id' => survey_deployment.id,
                'start_date' => survey_deployment.start_date, 
                'end_date' => survey_deployment.end_date, 
                'parent_id' => ap.parent_id, 
                'participant_id' => ap.id,
                'global_survey_id' => survey_deployment.global_survey_id
              ]
            end
          end
        end
      end
    end
  end
def pending_surveys unless session [ :user ] redirect_to '/' return end course_participants = CourseParticipant . where ( user_id : session [ :user ] . id ) assignment_participants = AssignmentParticipant . where ( user_id : session [ :user ] . id ) @surveys = [ ] if course_participants course_participants . each do | cp | survey_deployments = CourseSurveyDeployment . where ( parent_id : cp . parent_id ) if survey_deployments survey_deployments . each do | survey_deployment | if survey_deployment && Time . now > survey_deployment . start_date && Time . now < survey_deployment . end_date @surveys << [ 'survey' => Questionnaire . find ( survey_deployment . questionnaire_id ) , 'survey_deployment_id' => survey_deployment . id , 'start_date' => survey_deployment . start_date , 'end_date' => survey_deployment . end_date , 'parent_id' => cp . parent_id , 'participant_id' => cp . id , 'global_survey_id' => survey_deployment . global_survey_id ] end end end end end if assignment_participants assignment_participants . each do | ap | survey_deployments = AssignmentSurveyDeployment . where ( parent_id : ap . parent_id ) if survey_deployments survey_deployments . each do | survey_deployment | if survey_deployment && Time . now > survey_deployment . start_date && Time . now < survey_deployment . end_date @surveys << [ 'survey' => Questionnaire . find ( survey_deployment . questionnaire_id ) , 'survey_deployment_id' => survey_deployment . id , 'start_date' => survey_deployment . start_date , 'end_date' => survey_deployment . end_date , 'parent_id' => ap . parent_id , 'participant_id' => ap . id , 'global_survey_id' => survey_deployment . global_survey_id ] end end end end end end
This method should be moved to survey_deployment_contoller.rb
This method should be moved to survey_deployment_contoller . rb
# Check for a valid user # Get all the participant(course or assignment) entries for this user # Get all the course survey deployments for this user # Get all the assignment survey deployments for this user