Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TeacherController < ApplicationController
- #User has to login first before access
- before_filter :authorize, :except => [:login, :logout]
- # def create_multipart_test
- # if(params[:commit])
- # @question = Question.new
- # @question.make("Literacy", "Multipart Master test", "Test", "Multipart", "This is some test text!", "", 10,"master")
- # @question.question_type = "Literacy"
- # @question.depreciated = false
- # @question.save
- #
- # @question1 = Question.new
- # @question1.make("Literacy", "Multipart Slave test", "Test", "True False", "This is true!", "1", "10","slave",@question.id)
- # @question1.add_choice("True")
- # @question1.add_choice("False")
- # @question1.question_type = "Literacy"
- # @question1.depreciated = false
- # @question1.save
- #
- # flash[:notice] = "Made it!"
- # redirect_to :action=>:index
- # end
- # end
- #Determine the login ID, if it's a teacher/student/admin login
- #Check for password and set the session
- def login
- session[:student_id] = nil
- session[:teacher_id] = nil
- session[:admin_id] = nil
- if request.post?
- student = Student.authenticate(params[:name], params[:password])
- teacher = Teacher.authenticate(params[:name], params[:password])
- admin = Admin.authenticate(params[:name], params[:password])
- if teacher
- logger.info("Setting session teacher")
- session[:teacher_id] = teacher.id
- redirect_to({ :controller => :teacher, :action => "index" })
- elsif student
- logger.info("setting session student")
- session[:student_id] = student.id
- uri = session[:original_uri]
- session[:original_uri] = nil
- redirect_to(uri || { :action => "introduction" })
- elsif admin
- logger.info("Setting session admin")
- session[:admin_id] = admin.id
- redirect_to({ :controller => :admin, :action => "index" })
- else
- logger.info("Bad password")
- flash[:notice] = "Invalid User Name/Password"
- end
- end
- end
- #log out by reset_session
- def logout
- @exam = false
- reset_session
- respond_to do |format|
- format.html
- end
- end
- #Show all exams available for teacher
- def index
- @exam = false
- @exams = Exam.find(:all , :conditions=>{:status=>1})
- #Display username when logged in
- #Edited at 2.40pm 01/05/2009 by Nhi
- #Change1
- @teacher = Teacher.find_by_id(session[:teacher_id])
- end
- def old_exams
- @exam = false
- @exams = Exam.find(:all , :conditions=>{:status=>0}, :order=>'name ASC, updated_at DESC')
- end
- #Not applicable
- def edit
- end
- #Arrange the question
- def arrange
- @exam = false
- if params[:id]
- @exam = Exam.find_by_id(params[:id])
- eq = ExamQuestion.find_all_by_exam_id(@exam.id, :order => :position)
- @questions = Array.new
- for e in eq
- @questions.push(Question.find_by_id(e.question_id))
- end
- @questions.delete_at(0)
- else
- redirect_to(:action=>:arrange, :id=>params[:exam_selection])
- end
- end
- def save_order
- @exam = Exam.find_by_id(params[:exam_id])
- #@exam.status = 0
- a = (params[:result][:answer]).split(',')
- @st_exam = StudentExam.find_by_exam_id(params[:exam_id])
- unless @st_exam == nil
- exam = @exam.clone
- exam.save
- @exam.status = 0
- @exam.save
- @exam = exam
- @exam.add_question(1, :first=>true)
- end
- logger.debug(@exam.inspect)
- #sets all question in exam to position of -1
- #ExamQuestion.update_all("position = -1 ","exam_id = #{@exam.id}")
- @eq = Array.new(ExamQuestion.find_all_by_exam_id(@exam.id))
- @eq.each {|e| e.position = -1 }
- a.insert(0, 1)
- logger.info(a.inspect)
- ExamQuestion.update_all("position = -1","exam_id = #{@exam.id}")
- i = 0; until i == a.length
- eq = ExamQuestion.find_by_exam_id_and_question_id(@exam.id, a[i].to_i)
- unless eq.nil?
- eq.update_attribute(:position, i)
- eq.save
- else
- if Question.find_by_id(a[i].to_i).get_type == :master
- logger.info("multipart")
- @exam.add_multipart(a[i].to_i)
- else
- logger.info("single")
- @exam.add_question(a[i].to_i)
- #updates the position in the exam questions table of new questions that have been added
- ExamQuestion.update_all("position = #{i}","exam_id = #{@exam.id} AND question_id=#{a[i].to_i}")
- end
- end
- i += 1
- end
- #deletes any rows that haven't been updated with a new position
- #ie any question removed from the exam will be deleted from the database
- ExamQuestion.delete_all("exam_id = #{@exam.id} AND position = -1")
- @questions = Array.new(@exam.questions.find(:all))
- #redirect_to :action => :assign, :id => @exam.id
- if params[:commit] == "Save Question List and Display Question Types"
- redirect_to :action => :add_questions, :id => @exam.id, :e_type =>params[:e_type], :q_type =>params[:q_type]
- else
- redirect_to :action => :assign, :id => @exam.id
- end
- end
- #
- def add_questions
- if params[:commit] == "Mark or View Student Assessment Results" #|| "View Student Reports"
- redirect_to(:action=>:exam_results, :id=>params[:exam_selection])
- elsif params[:commit] == "View Old Exams"
- redirect_to(:action=>:old_exams )
- elsif params[:commit] == "Unassign Students from Selected Assessment"
- redirect_to(:action=>:unassign_exam, :id=>params[:exam_selection])
- else
- @exam = false
- if params[:id]
- if params[:commit] == "Next: Arrange Questions"
- redirect_to(:action=>:arrange, :id=>params[:id])
- else
- @exam = Exam.find_by_id(params[:id])
- if params[:e_type] == 'All'
- @questions = Array.new(Question.find(:all,:conditions=>["question_type <> 'New' AND question_type <> 'End' AND master_id is null"]))
- @exam_questions = Array.new(@exam.questions.find(:all, :conditions=>["question_type <> 'New'"]))
- else
- if params[:q_type]
- @questions = Array.new(Question.find(:all,:conditions=>{:master_id=>nil}))
- ones_of_right_type = Array.new
- @questions.each { |q|
- if q.get_type_string(params[:q_type])==q.get_type && q.question_type!='End' && q.question_type!='New'
- logger.debug("q.get_type: " + q.get_type.to_s)
- logger.debug("q_type: " + params[:q_type])
- ones_of_right_type.push q
- end
- }
- @questions = ones_of_right_type
- @exam_questions = Array.new(@exam.questions.find(:all, :order => 'position asc'))
- else
- @questions = Array.new(Question.find(:all,:conditions=>{:question_type => @exam.exam_type,:master_id=>nil}))
- @exam_questions = Array.new(@exam.questions.find(:all, :conditions=>["question_type <> 'New'"]))
- end
- end
- end
- else
- if params[:exam_selection]
- if params[:commit] == "Assign Students to Selected Assessment"
- redirect_to(:action=>:assign, :id=>params[:exam_selection])
- else
- redirect_to(:action=>:add_questions, :id=>params[:exam_selection])
- end
- else
- flash[:notice] = "Select an exam to edit"
- redirect_to(:action=>:index)
- end
- end
- end
- end
- def add
- @exam = Exam.find_by_id(params[:exam_id])
- unless @exam.exam_questions.find_by_question_id_and_exam_id(params[:question_id], @exam.id)
- if Question.find_by_id(params[:question_id]).get_type == :master
- logger.info("multipart")
- @exam.add_multipart(params[:question_id])
- else
- logger.info("single")
- @exam.add_question(params[:question_id])
- end
- flash[:notice] = "Question id " + params[:question_id] + " added to exam."
- else
- flash[:notice] = "You have added this question already. You may change the order at the Arrange page"
- end
- redirect_to(:action => :add_questions, :id => params[:exam_id])
- end
- #When assign to student button clicked/ Display success message
- #Edited at 12.45pm 06/05/2009 by Nhi
- def assign
- @exam = Exam.find_by_id(params[:id])
- @students = Student.find(:all)
- if params[:student]
- @students_assigned = Array.new #change1
- for student in @students
- if params[:student][student.id.to_s][:assign] == 1.to_s
- student.assign_exam(@exam.id)
- @students_assigned.push student # change2
- end
- end
- a = ""
- @students_assigned.each {|e| a+= e.name; a += ", " unless e == @students_assigned.last }
- flash[:notice] = "Students Assigned to test: " + a
- else
- end
- end
- def unassign_exam
- @exam = Exam.find(params[:id])
- @students = Student.find(:all)
- @st_exams = StudentExam.find_all_by_exam_id(@exam.id)
- if params[:st_exam]
- for st_exam in @st_exams
- if params[:st_exam][st_exam.id.to_s][:unassign_exam] == "1"
- st_exam.destroy
- flash[:notice] = "Test was successfully unassigned."
- redirect_to(:action =>:index)
- end
- end
- end
- end
- def create_new_exam
- @exam = Exam.new
- if params[:exam]
- @exam = Exam.new(params[:exam])
- if @exam.make(:e_name=>params[:exam][:name], :exam_type=>params[:exam_type], :e_status=> 1, :e_skippable => 1, :e_results_viewable=>params[:viewable]) #CHANGE WHEN INTERFACE IS FINISHED, added in default e_status
- if @exam.save
- @exam.add_question(1, :first=>true)
- @exam.add_question(2)
- redirect_to(:action=>:add_questions, :id=>@exam.id)
- end
- else
- flash[:notice] = "<div id = errorMessage> You can only add an exam of the same name once </div>"
- redirect_to :action=>:index
- end
- end
- end
- def report
- @exam = Exam.find_by_id(params[:id])
- @st_exam = StudentExam.find_by_id(params[:subid])
- logger.debug("student_exam: " + @st_exam.inspect)
- @subcategories = @exam.get_subcategories
- @exam_questions = Array.new(@exam.questions.find(:all))
- end
- def exam_results
- @exam = Exam.find_by_id(params[:id]) || false
- @st_exams = StudentExam.find_all_by_exam_id(@exam.id)
- if @st_exams.nil? || @st_exams.empty?
- flash[:notice] = "Please select an exam before chosing view student report"
- redirect_to :action=>:index
- end
- end
- def save_new_question
- @question = Question.new
- case params[:q_type]
- when "Multipart"
- logger.debug("MULTIPART")
- @question.make(params[:question_type], params[:q_subcategory], params[:q_summary], params[:q_type], params[:q_text], "", 10, "master")
- redirect_to(:action=>'sub_multipart', :id=>@question.id)
- logger.debug("redirecting to sub_multipart")
- return
- when "Sub_Multipart"
- logger.debug("sub multipart")
- @question1 = Question.new
- @question1.make(params[:question_type], params[:q_subcategory], "SLAVE QUESTION", "Long Answer", params[:q_long_text],nil,10,"slave",params[:id])
- @question1.question_type = params[:question_type]
- @question1.depreciated = false
- @question1.save
- @question2 = Question.new
- @question2.make(params[:question_type], params[:q_subcategory], "SLAVE QUESTION", "Short Answer", params[:q_short_text],nil,10,"slave",params[:id])
- @question2.question_type = params[:question_type]
- @question2.depreciated = false
- @question2.save
- @question3 = Question.new
- @question3.make(params[:question_type],params[:q_subcategory], "SLAVE QUESTION", "True False",params[:q_tf_text],params[:q_asw],params[:q_weight],"slave",params[:id])
- @question3.question_type = params[:question_type]
- @question3.depreciated = false
- @question3.save
- when "Multiple Choice"
- error_messages = ""
- error_messages = @question.make(params[:q_category], params[:q_subcategory], params[:q_summary],"Multiple Choice",params[:q_text],params[:asw],params[:q_weight])
- error_messages = "" if error_messages == true
- blank_word = false
- params[:question].each do |key,value|
- blank_word = true if value[:q_asw].blank?
- end
- error_messages += "Error: Please enter a word into all of the option boxes." if blank_word
- if error_messages.blank?
- #if no errors, continue and add choices
- params[:question].each do |key,value|
- @question.add_choice(value[:q_asw])
- end
- else
- #otherwise, display the error messages
- flash[:error] = "<h2><font color=red>" + error_messages + "</font></h2>"
- flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- options = params[:parts]
- redirect_to(:action=>'main_form', :choices=>options) # refresh the page so the error messages show
- return
- end
- when "Sequence"
- answer = ""
- blank_word = false
- blank_answer = false
- wrong_answer = false
- answer_total = 0
- right_answer_total = 0
- i = 1
- possible_answers = Array.new
- while i <= params[:parts].to_i
- right_answer_total += i
- possible_answers.push(i.to_s)
- i += 1
- end
- params[:question].each do |key,value|
- answer = answer + value[:q_answer] + ","
- blank_word = true if value[:q_part].blank? == true
- blank_answer = true if value[:q_answer].blank? == true
- answer_total += value[:q_answer].to_i
- wrong_answer = true unless possible_answers.include?(value[:q_answer])
- end
- error_messages = @question.make(params[:q_category], params[:q_subcategory], params[:q_summary],"Sequence",params[:q_text],answer,params[:q_weight])
- error_messages = "" if error_messages == true
- error_messages += "Error: Must write in all word boxes.<br>" if blank_word == true
- error_messages += "Error: Must write in all answer boxes.<br>" if blank_answer == true
- error_messages += "Error: One of your answers was outside the valid range.<br>" if wrong_answer == true
- error_messages += "Error: Your answers do not add up to the right amount.<br>" if right_answer_total != answer_total
- if error_messages.blank?
- params[:question].each do |key,value|
- @question.add_choice(value[:q_part])
- end
- else
- flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- redirect_to :action=>'main_form', :parts=>params[:parts]
- return
- end
- when "True False"
- #make question, storing error messages in a string
- error_messages = @question.make(params[:q_category],params[:q_subcategory],params[:q_summary],"True False",params[:q_text],params[:q_asw],params[:q_weight])
- #clear error messages if question.make returned true
- error_messages = "" if error_messages == true
- #display error messages if they exist
- unless error_messages.blank?
- flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- render :partial=>'truefalse', :layout=>true #refresh the page
- return #do not continue
- end
- #add the choices to the question so it displays properly to the student
- @question.add_choice("True")
- @question.add_choice("False")
- when "Multiple Short Answer"
- answer = ""
- blank_word = false
- params[:question].each do |key,value|
- answer = answer + value[:q_answer] + "," #create answer string for question making
- blank_word = true if value[:q_answer].blank? #check if answer box is blank
- blank_word = true if value[:q_part].blank? #check if question part text is blank
- end
- error_messages = @question.make(params[:q_category], params[:q_subcategory], params[:q_summary], "Multiple Short Answer", params[:q_text], answer, params[:weight])
- error_messages = "" if error_messages == true
- error_messages += "Error: Please enter text into all of the question and answer boxes." if blank_word == true
- #add choices if error messages are blank
- if error_messages.blank?
- params[:question].each do |key,value|
- @question.add_choice(value[:q_part])
- end
- else #display error messages if they exist
- flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- redirect_to :action=>'main_form', :parts=>params[:parts]
- return
- end
- when "Arrange Order"
- answer = ""
- params[:question].each do |key,value|
- answer = answer + value[:q_answer] + ","
- end
- error_messages = @question.make(params[:q_category], params[:q_subcategory], params[:q_summary], "Arrange Order", params[:q_text], answer, params[:weight])
- error_messages = "" if error_messages == true
- blank_word == false
- params[:question].each do |key,value|
- blank_word = true if value[:q_part].blank?
- end
- params[:question].each do |key,value|
- blank_word = true if value[:q_answer].blank?
- end
- if(blank_word)
- error_messages = error_messages + "Error: You must enter text in all of the boxes. Please review your question text and answers.<br>"
- end
- unless error_messages.blank?
- flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- redirect_to :action=>'main_form', :choices=>params[:parts]
- return
- end
- params[:question].each do |key,value|
- @question.add_choice(value[:q_part])
- end
- when "Select Wrong Word"
- #make question and store error messages in error_messages string
- error_messages = @question.make(params[:q_category], params[:q_subcategory], params[:q_summary],"Select Wrong Word",params[:q_text],params[:q_asw],params[:q_weight])
- #clear error_messages if question.make returns true
- error_messages = "" if error_messages == true
- blank_word = false
- #check all option boxes are written in
- params[:question].each do |key,value|
- blank_word = true if value[:q_option].blank?
- end
- if(blank_word == true)
- error_messages = error_messages + "Error: You must write in all of the option boxes.<br>"
- end
- #display the error messages if they exist
- unless error_messages.blank?
- flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- options = params[:q_options]
- redirect_to(:action=>'main_form', :choices=>options) # refresh the page so the error messages show
- return
- else #otherwise, add all the choices to the question and continue
- params[:question].each do |key,value|
- @question.add_choice(value[:q_option])
- end
- end
- when "Arrange Alphabetical"
- answer = ""
- #create answer string to use when making question
- params[:question].each do |key,value|
- answer = answer + value[:q_answer] + ","
- end
- error_messages = @question.make(params[:q_category], params[:q_subcategory], params[:q_summary],"Arrange Alphabetical",params[:q_text],answer,params[:q_weight])
- error_messages = "" if error_messages == true
- #check all option boxes are written in
- blank_word = false
- params[:question].each do |key,value|
- blank_word = true if value[:q_part].blank?
- end
- error_messages += "Error: Please write in all option boxes.<br>" if blank_word == true
- #check all answer boxes are written in
- blank_answer = false
- params[:question].each do |key,value|
- blank_answer == true if value[:q_answer].blank?
- end
- error_messages += "Error: Please write in all answer boxes.<br>" if blank_answer == true
- #check answers add up to the right total
- right_total = 0
- i = 1
- while i <= params[:options].to_i
- right_total += i
- i += 1
- end
- q_ans_total = 0
- params[:question].each do |key,value|
- q_ans_total += value[:q_answer].to_i
- end
- if q_ans_total != right_total
- error_messages += "Error: Your answers do not add up to the right total. Please review your answers.<br>"
- end
- #check all answers are in the correct range
- correct_range = Array.new
- i = 1
- while i <= params[:options].to_i
- correct_range.push(i.to_s)
- i += 1
- end
- wrong_value = false
- params[:question].each do |key,value|
- wrong_value = true unless correct_range.include?(value[:q_answer])
- end
- error_messages += "Error: At least one of your answers is outside the valid range.<br>" if wrong_value == true
- #display error messages unless they are blank
- unless error_messages.blank?
- flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- options = params[:options]
- redirect_to(:action=>'main_form', :parts=>options) # refresh the page so the error messages show
- return
- else #if error messages are blank, add all options to the question and continue (will be saved at end of method)
- params[:question].each do |key,value|
- @question.add_choice(value[:q_part])
- end
- end
- params[:question].each do |key,value|
- @question.add_choice(value[:q_part])
- end
- when "Word Match" #to create a question of type "Word Match"
- answer = ""
- #create answer string to use when making question
- params[:question].each do |key,value|
- answer = answer + value[:answer].to_s + ","
- end
- error_messages = "" #clear error messages
- error_messages = @question.make(params[:q_category], params[:q_subcategory], params[:q_summary], "Word Match", params[:q_text], answer, params[:q_weight])
- error_messages = "" if error_messages == true
- #check if all word and match boxes are filled
- blank_word = false
- params[:question].each do |key,value|
- blank_word = true if value[:word].blank? || value[:match].blank?
- end
- if blank_word
- error_messages = error_messages + "Error: You have at least one blank word box. Please enter something into every word box.<br>"
- end
- # set up valid answers
- # what should the answers add up to
- answer_invalid = false
- right_total = 0
- total = 0
- i = 1
- while i <= params[:options].to_i
- right_total = right_total + i
- i = i + 1
- end
- # what are all the correct possible answers
- possible_answers = Array.new()
- i = 1
- while i <= params[:options].to_i
- possible_answers.push(i.to_s)
- i = i+1
- end
- #add up all the answers to check if they are all there,
- #and also check if they are a valid number
- params[:question].each do |key,value|
- total = total + value[:answer].to_i
- unless possible_answers.include?(value[:answer].to_s)
- answer_invalid = true
- end
- end
- if total != right_total
- answer_invalid = true
- end
- if answer_invalid
- error_messages = error_messages + "Error: Answers invalid. Please review your answers in the \"Matches to Number\" column."
- end
- flash[:error] = "" #clear error messages
- #display error messages if they exist
- unless error_messages.blank? || error_messages == true #when there are error messages and question making was unsuccessful
- flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>" #put error messages on the page
- #@blah = Question.new(:q_summary=>params[:q_summary]) # save the text the user has already entered
- #render(:action=>'create_wordmatch', :object=>@blah) # refresh the page so the error messages show
- options = params[:options]
- redirect_to(:action=>'main_form', :choices=>options) # refresh the page so the error messages show
- return #do not continue making the question if errors are found
- else #if no errors, add the choices to the question
- params[:question].each do |key,value|
- @question.add_choice(value[:word], "word")
- end
- params[:question].each do |key,value|
- @question.add_choice(value[:match], "match")
- end
- end
- when "Calculation"
- answer = ""
- #create answer string to use when creating question
- params[:question].each do |key,value|
- answer = answer + value[:q_answer] + ","
- end
- # make question and store error messages
- error_messages = @question.make(params[:q_category], params[:q_subcategory], params[:q_summary], "Calculation", params[:q_text], answer, params[:weight])
- # if question.make is true (successful), clear the error messages
- error_messages = "" if error_messages == true
- blank_word == false
- #check if the user left any word boxes blank
- params[:question].each do |key,value|
- blank_word = true if value[:q_part].blank?
- end
- params[:question].each do |key,value|
- blank_word = true if value[:q_answer].blank?
- end
- if(blank_word)
- error_messages = error_messages + "Error: You must enter text in all of the boxes. Please review your question text and answers.<br>"
- end
- flash[:error] == ""
- #display the error messages unless they are blank
- unless error_messages.blank?
- flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- options = params[:parts]
- redirect_to(:action => 'main_form', :parts=>options)
- return
- #if there are no error messages, add all the question choices to the question and continue
- #(question will be saved at the end of this method)
- else
- params[:question].each do |key,value|
- @question.add_choice(value[:q_part])
- end
- end
- when "Fill in Blanks"
- answer = ""
- #create the answer string to be used when making the question later
- params[:question].each do |key,value|
- answer = answer + value[:q_blank] + ","
- end
- blanks = params[:q_text].scan('%%%') #array of '%%%' is stored in blanks
- error_messages = ""
- if blanks.size != (params[:q_amount].to_i)
- error_messages += "Error: You have the wrong number of blank spaces in your question text. Please enter %%% instead of the word anywhere you want a blank to be.<br>"
- end
- #create question and store errors in make_errors string
- make_errors = @question.make(params[:q_category], params[:q_subcategory], params[:q_summary], "Fill in Blanks", params[:q_text], answer,params[:weight])
- error_messages += make_errors unless make_errors == true
- #check all word boxes have text
- blank_word = false
- params[:question].each do |key,value|
- blank_word = true if value[:q_blank].blank?
- end
- error_messages += "Error: Please enter a word into all of the blank word boxes.<br>" if blank_word == true
- #display messages if error messages exist
- unless error_messages.blank?
- flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- options = params[:q_amount]
- redirect_to(:action => 'main_form', :parts=>options)
- return #do not continue processing (this means question will not be saved)
- end
- # when "Multipart"
- # @question.q_data = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
- # <question category=\"Literacy\" subcategory=\"Multipart\">
- # <qtype>Multipart</qtype>
- # <qtext>" + params[:q_text] + "</qtext>
- # <qsummary>" + params[:q_summary] + "</qsummary>
- # </question>"
- #
- # @question.question_type = "Literacy"
- # @question.depreciated = false
- # @question.save
- when "Spelling"
- error_messages = @question.make(params[:q_category], params[:q_subcategory], params[:q_summary],"Spelling","random",params[:q_asw],params[:q_weight])
- #clear error_messages if question.make returns true
- error_messages = "" if error_messages == true
- blank_answer = false
- blank_word = false
- #check all option boxes are written in
- params[:question].each do |key,value|
- blank_word = true if value[:T1].blank?
- blank_word = true if value[:T2].blank?
- blank_word = true if value[:T3].blank?
- blank_answer = true if value[:T4].blank?
- end
- if(blank_word == true)
- error_messages = error_messages + "Error: You must write in all of the option boxes.<br>"
- end
- if(blank_answer == true)
- error_messages = error_messages + "Error: Answer not inputted correctly.<br>"
- end
- #display the error messages if they exist
- unless error_messages.blank?
- flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- options = params[:parts]
- redirect_to(:action=>'main_form', :choices=>options) # refresh the page so the error messages show
- return
- else
- q_data = " "
- q_data = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
- <question category=\""+ params[:q_category] +"\" subcategory=\"" + params[:q_subcategory] + "\">
- <qtype>Spelling</qtype>"
- #<qtext>" + params[:q_text] + "</qtext>
- q_data +="<qamount> "+ (params[:parts].to_i * 3).to_s + "</qamount>"
- q_data+= "<qsummary>" + params[:q_summary] + "</qsummary>"
- i = 1; x = 0
- params[:question].each do |key, value|
- q_data +=
- "<q id=\"#{i}\" subid=\"#{x+1}\">" + value[:T1] + "</q>" +
- "<q id=\"#{i}\" subid=\"#{x+2}\">" + value[:T2] + "</q>" +
- "<q id=\"#{i}\" subid=\"#{x+3}\">" + value[:T3] + "</q>"
- i += 1
- end
- q_data += "<asw>"
- params[:question].each do |key, value|
- q_data+= value[:T4] + ","
- end
- q_data +="</asw>
- <weight>" + params[:q_weight] + "</weight>
- </question>"
- @question.q_data = q_data
- @question.question_type = params[:q_category]
- @question.depreciated = false
- @question.save
- end
- when "Short Answer"
- #make question and store error messages in error_messages string
- error_messages = @question.make(params[:q_category],params[:q_subcategory],params[:q_summary],"Short Answer",params[:q_text],params[:q_asw],params[:q_weight])
- #if question.make() returned true, clear error messages
- error_messages = "" if error_messages == true
- #display error messages unless they are blank (which would mean there are none)
- unless error_messages.blank?
- flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- render :partial => 'shortanswer', :layout=>true
- return
- end
- else #To create a question of any other type (at the moment only long answer)
- logger.debug("Reached else")
- error_messages = @question.make(params[:question_type], params[:q_subcategory], params[:q_summary], params[:q_type], params[:q_text],params[:q_asw]) #weight should be added when question weighting implemented
- error_messages = "" if error_messages == true
- if error_messages.blank?
- @question.question_type = params[:question_type]
- @question.depreciated = false
- @question.save
- else
- flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- render :partial=> 'longanswer', :layout=>true
- return
- end
- end
- @question.question_type = "Literacy" if @question.question_type.nil?
- #this is for all question types
- logger.debug("question: " + @question.inspect + params[:question].to_s)
- logger.debug("Make question success")
- if @question
- # if @question.get_type == :multiple #|| @question.get_type == :true_false
- # logger.debug("Redirecting to add_choices")
- # redirect_to(:action=>:add_choices, :id=>@question.id, :choices=>params[:q_choices])
- # else
- flash[:notice] = "Question was successfully created."
- redirect_to(:action =>:index)
- #end
- else
- render :action => "new_question"
- end
- end
- # def xml_snq
- # render :=>"teacher/create_wordmatch?choices=5", :layout=>false
- # end
- #show students results
- def student_results
- @exam = false
- @st_exam = StudentExam.find_by_id(params[:id])
- #Notification of skipped question when teacher views student result
- #Edited at 11.45pm 15/05/2009 by Nhi
- #change1
- @skipped = Array.new(Result.find(:all, :conditions=>{:student_exam_id=>@st_exam.id, :answer=>"Skipped"}))
- #End of change
- @results = Array.new(Result.find_all_by_student_exam_id(@st_exam.id))
- #change2
- @results.delete_if {|s| s.answer == "Skipped" }
- #End of change
- if params[:r_mark]
- for result in @results
- if params[:r_mark].include?(result.id.to_s)
- result.score = "1"
- else
- result.score = "0"
- end
- #saves the marked result to the result table
- result.marked = true
- result.save
- end
- end
- end
- def main_form
- if params[:type]
- case params[:type]
- when "Please Select An Option Below"
- render :partial=>'nullpage'
- when "Multiple Choice"
- @type = 'multiplechoice'
- render :partial=>'choices'
- when "True False"
- render :partial=>'truefalse'
- when "Word Match"
- @type = 'wordmatch'
- render :partial=>'choices'
- when "Sequence"
- @type = 'sequence'
- render :partial=>'choices'
- when "Arrange Alphabetical"
- @type = 'arrangealpha'
- render :partial=>'choices'
- when "Arrange Order"
- @type = 'arrangeorder'
- render :partial=>'choices'
- when "Fill Blanks"
- @type = 'fillblanks'
- render :partial=>'choices'
- when "Wrong Word"
- @type = 'wrongword'
- render :partial=>'choices'
- when "Long Answer"
- render :partial=>'longanswer'
- when "Short Answer"
- render :partial=>'shortanswer'
- when "Spelling"
- @type = 'spelling'
- render :partial=>'choices'
- when "Calculation"
- @type = 'calculation'
- render :partial=>'choices'
- when "Multiple Short Answer"
- @type = 'multipleshortanswer'
- render :partial=>'choices'
- when "Multipart"
- render :partial=>'multipart'
- end
- end
- end
- def choices
- #if
- @choices = params[:partamount].to_i
- if(@choices <= 0)
- flash[:error1] = "<h1><font color=red>Choices must be numeric and greater than 0</font></h1>"
- render :partial=>'error_page'
- else
- case params[:q_type]
- when 'calculation'
- render :partial => 'create_calculation'
- when 'wordmatch'
- render :partial => 'create_wordmatch'
- when 'arrangealpha'
- render :partial => 'create_arrangealpha'
- when 'wrongword'
- render :partial => 'create_wrongword'
- when 'arrangeorder'
- render :partial => 'create_arrangeorder'
- when 'sequence'
- render :partial => 'create_sequence'
- when 'spelling'
- render :partial => 'create_spelling'
- when 'multipleshortanswer'
- render :partial => 'create_multipleshortanswer'
- when 'multiplechoice'
- render :partial => 'create_multiplechoice'
- when 'fillblanks'
- render :partial => 'create_fillblanks'
- end
- end
- end
- def edit_exam
- @exam = Exam.find(params[:id])
- @questions = @exam.questions.find(:all)
- @all_questions = Question.find(:all)
- end
- #Update the exam, find the exam ID , then update the exam
- def update_exam
- @exam = Exam.find(params[:id])
- respond_to do |format|
- if @exam.update_attributes(params[:exam])
- flash[:notice] = "Exam #{@exam.name} was successfully updated."
- format.html { redirect_to(:action=>:index) }
- else
- format.html { render :action => "edit_exam" }
- end
- end
- end
- def show_help
- #gets ID for question data from the help index then displays the question to the teacher.
- #currently needs work as the question is shown in its XML format, other than that its fine!
- #Created by Eian Blacklock // LAST EDITED June 1st 2009
- @question = Question.find(params[:id])
- respond_to do |format|
- format.html
- format.xml { render :xml => @question }
- end
- end
- def add_help
- #used to create a new help record.
- #@questions contains all questions and is used for the drop down list when it is implemented.
- #Created by Eian Blacklock // LAST EDITED June 1st 2009
- @questions = Question.find(:all)
- @help = Help.new
- end
- def create_help
- # this will allow the teacher to create new help - Eian
- # takes object :help passed in from add help page and makes a new help record in table
- # Logger simply adds information to the development log and is not integral to the method.
- # Created by Eian Blacklock // LAST EDITED June 1st 2009
- @help = Help.new(params[:help])
- @help.save
- logger.info(@help.inspect)
- redirect_to :action=>:help_index
- end
- def help_index
- #Created by Eian Blacklock // LAST EDITED June 1st 2009
- @helps = Help.find(:all, :order => :question_id)
- respond_to do |format|
- format.html
- end
- end
- def edit_help
- #this will allow the teacher to edit existing help with update_help
- #Created by Eian Blacklock // LAST EDITED June 1st 2009
- @help = Help.find(params[:id])
- end
- def update_help
- #Created by Eian Blacklock // LAST EDITED June 1st 2009
- @help = Help.find(params[:id])
- respond_to do |format|
- if @help.update_attributes(params[:help])
- flash[:notice] = "Help data for question #{@help.question_id} was successfully updated."
- format.html { redirect_to(:action => :help_index) }
- else
- format.html { render :action => "edit_help" }
- end
- logger.info(@help.inspect)
- end
- end
- protected
- def authorize
- unless Teacher.find_by_id(session[:teacher_id])
- session[:original_uri] = request.request_uri
- flash[:notice] = "Please login with your user name and password."
- redirect_to :controller => :student, :action => :login
- end
- end
- def authorized?
- unless Teacher.find_by_id(session[:teacher_id])
- return false
- else
- return true
- end
- end
- end
- class TeacherController < ApplicationController
- #User has to login first before access
- before_filter :authorize, :except => [:login, :logout]
- #Determine the login ID, if it's a teacher/student/admin login
- #Check for password and set the session
- def login
- session[:student_id] = nil
- session[:teacher_id] = nil
- session[:admin_id] = nil
- if request.post?
- student = Student.authenticate(params[:name], params[:password])
- teacher = Teacher.authenticate(params[:name], params[:password])
- admin = Admin.authenticate(params[:name], params[:password])
- if teacher
- logger.info("Setting session teacher")
- session[:teacher_id] = teacher.id
- redirect_to({ :controller => :teacher, :action => "index" })
- elsif student
- logger.info("setting session student")
- session[:student_id] = student.id
- uri = session[:original_uri]
- session[:original_uri] = nil
- redirect_to(uri || { :action => "introduction" })
- elsif admin
- logger.info("Setting session admin")
- session[:admin_id] = admin.id
- redirect_to({ :controller => :admin, :action => "index" })
- else
- logger.info("Bad password")
- flash[:notice] = "Invalid User Name/Password"
- end
- end
- end
- #log out by reset_session
- def logout
- @exam = false
- reset_session
- respond_to do |format|
- format.html
- end
- end
- #Show all exams available for teacher
- def index
- @exam = false
- @exams = Exam.find(:all , :conditions=>{:status=>1})
- #Display username when logged in
- #Edited at 2.40pm 01/05/2009 by Nhi
- #Change1
- @teacher = Teacher.find_by_id(session[:teacher_id])
- end
- def old_exams
- @exam = false
- @exams = Exam.find(:all , :conditions=>{:status=>0}, :order=>'name ASC, updated_at DESC')
- end
- #Not applicable
- def edit
- end
- #Arrange the question
- def arrange
- @exam = false
- if params[:id]
- @exam = Exam.find_by_id(params[:id])
- eq = ExamQuestion.find_all_by_exam_id(@exam.id, :order => :position)
- @questions = Array.new
- for e in eq
- @questions.push(Question.find_by_id(e.question_id))
- end
- @questions.delete_at(0)
- else
- redirect_to(:action=>:arrange, :id=>params[:exam_selection])
- end
- end
- def save_order
- @exam = Exam.find_by_id(params[:exam_id])
- #@exam.status = 0
- a = (params[:result][:answer]).split(',')
- @st_exam = StudentExam.find_by_exam_id(params[:exam_id])
- unless @st_exam == nil
- exam = @exam.clone
- exam.save
- @exam.status = 0
- @exam.save
- @exam = exam
- @exam.add_question(1, :first=>true)
- end
- logger.debug(@exam.inspect)
- #sets all question in exam to position of -1
- #ExamQuestion.update_all("position = -1 ","exam_id = #{@exam.id}")
- @eq = Array.new(ExamQuestion.find_all_by_exam_id(@exam.id))
- @eq.each {|e| e.position = -1 }
- a.insert(0, 1)
- logger.info(a.inspect)
- ExamQuestion.update_all("position = -1","exam_id = #{@exam.id}")
- i = 0; until i == a.length
- eq = ExamQuestion.find_by_exam_id_and_question_id(@exam.id, a[i].to_i)
- unless eq.nil?
- eq.update_attribute(:position, i)
- eq.save
- else
- if Question.find_by_id(a[i].to_i).get_type == :master
- logger.info("multipart")
- @exam.add_multipart(a[i].to_i)
- else
- logger.info("single")
- @exam.add_question(a[i].to_i)
- #updates the position in the exam questions table of new questions that have been added
- ExamQuestion.update_all("position = #{i}","exam_id = #{@exam.id} AND question_id=#{a[i].to_i}")
- end
- end
- i += 1
- end
- #deletes any rows that haven't been updated with a new position
- #ie any question removed from the exam will be deleted from the database
- ExamQuestion.delete_all("exam_id = #{@exam.id} AND position = -1")
- @questions = Array.new(@exam.questions.find(:all))
- #redirect_to :action => :assign, :id => @exam.id
- if params[:commit] == "Save Question List and Display Question Types"
- redirect_to :action => :add_questions, :id => @exam.id, :e_type =>params[:e_type], :q_type =>params[:q_type]
- else
- redirect_to :action => :assign, :id => @exam.id
- end
- end
- #
- def add_questions
- if params[:commit] == "Mark or View Student Assessment Results" #|| "View Student Reports"
- redirect_to(:action=>:exam_results, :id=>params[:exam_selection])
- elsif params[:commit] == "View Old Exams"
- redirect_to(:action=>:old_exams )
- elsif params[:commit] == "Unassign Students from Selected Assessment"
- redirect_to(:action=>:unassign_exam, :id=>params[:exam_selection])
- else
- @exam = false
- if params[:id]
- if params[:commit] == "Next: Arrange Questions"
- redirect_to(:action=>:arrange, :id=>params[:id])
- else
- @exam = Exam.find_by_id(params[:id])
- if params[:e_type] == 'All'
- @questions = Array.new(Question.find(:all,:conditions=>["question_type <> 'New' AND question_type <> 'End' AND master_id is null"]))
- @exam_questions = Array.new(@exam.questions.find(:all, :conditions=>["question_type <> 'New'"]))
- else
- if params[:q_type]
- @questions = Array.new(Question.find(:all,:conditions=>{:master_id=>nil}))
- ones_of_right_type = Array.new
- @questions.each { |q|
- if q.get_type_string(params[:q_type])==q.get_type && q.question_type!='End' && q.question_type!='New'
- logger.debug("q.get_type: " + q.get_type.to_s)
- logger.debug("q_type: " + params[:q_type])
- ones_of_right_type.push q
- end
- }
- @questions = ones_of_right_type
- @exam_questions = Array.new(@exam.questions.find(:all, :order => 'position asc'))
- else
- @questions = Array.new(Question.find(:all,:conditions=>{:question_type => @exam.exam_type,:master_id=>nil}))
- @exam_questions = Array.new(@exam.questions.find(:all, :conditions=>["question_type <> 'New'"]))
- end
- end
- end
- else
- if params[:exam_selection]
- if params[:commit] == "Assign Students to Selected Assessment"
- redirect_to(:action=>:assign, :id=>params[:exam_selection])
- else
- redirect_to(:action=>:add_questions, :id=>params[:exam_selection])
- end
- else
- flash[:notice] = "Select an exam to edit"
- redirect_to(:action=>:index)
- end
- end
- end
- end
- def add
- @exam = Exam.find_by_id(params[:exam_id])
- unless @exam.exam_questions.find_by_question_id_and_exam_id(params[:question_id], @exam.id)
- if Question.find_by_id(params[:question_id]).get_type == :master
- logger.info("multipart")
- @exam.add_multipart(params[:question_id])
- else
- logger.info("single")
- @exam.add_question(params[:question_id])
- end
- flash[:notice] = "Question id " + params[:question_id] + " added to exam."
- else
- flash[:notice] = "You have added this question already. You may change the order at the Arrange page"
- end
- redirect_to(:action => :add_questions, :id => params[:exam_id])
- end
- #When assign to student button clicked/ Display success message
- #Edited at 12.45pm 06/05/2009 by Nhi
- def assign
- @exam = Exam.find_by_id(params[:id])
- @students = Student.find(:all)
- if params[:student]
- @students_assigned = Array.new #change1
- for student in @students
- if params[:student][student.id.to_s][:assign] == 1.to_s
- student.assign_exam(@exam.id)
- @students_assigned.push student # change2
- end
- end
- a = ""
- @students_assigned.each {|e| a+= e.name; a += ", " unless e == @students_assigned.last }
- flash[:notice] = "Students Assigned to test: " + a
- else
- end
- end
- def unassign_exam
- @exam = Exam.find(params[:id])
- @students = Student.find(:all)
- @st_exams = StudentExam.find_all_by_exam_id(@exam.id)
- if params[:st_exam]
- for st_exam in @st_exams
- if params[:st_exam][st_exam.id.to_s][:unassign_exam] == "1"
- st_exam.destroy
- flash[:notice] = "Test was successfully unassigned."
- redirect_to(:action =>:index)
- end
- end
- end
- end
- def create_new_exam
- @exam = Exam.new
- if params[:exam]
- @exam = Exam.new(params[:exam])
- if @exam.make(:e_name=>params[:exam][:name], :exam_type=>params[:exam_type], :e_status=> 1, :e_skippable => 1, :e_results_viewable=>params[:viewable]) #CHANGE WHEN INTERFACE IS FINISHED, added in default e_status
- if @exam.save
- @exam.add_question(1, :first=>true)
- @exam.add_question(2)
- redirect_to(:action=>:add_questions, :id=>@exam.id)
- end
- else
- flash[:notice] = "<div id = errorMessage> You can only add an exam of the same name once </div>"
- redirect_to :action=>:index
- end
- end
- end
- def report
- @exam = Exam.find_by_id(params[:id])
- @st_exam = StudentExam.find_by_id(params[:subid])
- logger.debug("student_exam: " + @st_exam.inspect)
- @subcategories = @exam.get_subcategories
- @exam_questions = Array.new(@exam.questions.find(:all))
- end
- def exam_results
- @exam = Exam.find_by_id(params[:id]) || false
- @st_exams = StudentExam.find_all_by_exam_id(@exam.id)
- if @st_exams.nil? || @st_exams.empty?
- flash[:notice] = "Please select an exam before chosing view student report"
- redirect_to :action=>:index
- end
- end
- # def save_new_question
- # @question = Question.new
- # case params[:q_type]
- #
- #
- # when "Multiple Choice"
- # error_messages = ""
- # error_messages = @question.make(params[:q_category], params[:q_subcategory], params[:q_summary],"Multiple Choice",params[:q_text],params[:asw],params[:q_weight])
- # error_messages = "" if error_messages == true
- # blank_word = false
- # params[:question].each do |key,value|
- # blank_word = true if value[:q_asw].blank?
- # end
- # error_messages += "Error: Please enter a word into all of the option boxes." if blank_word
- #
- # if error_messages.blank?
- # #if no errors, continue and add choices
- # params[:question].each do |key,value|
- # @question.add_choice(value[:q_asw])
- # end
- # else
- # flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- # options = params[:parts]
- # redirect_to(:action=>'main_form', :choices=>options) # refresh the page so the error messages show
- # return
- # end
- #
- #
- # when "Sequence"
- # answer = ""
- # blank_word = false
- # blank_answer = false
- # wrong_answer = false
- # answer_total = 0
- # right_answer_total = 0
- # i = 1
- # possible_answers = Array.new
- # while i <= params[:parts].to_i
- # right_answer_total += i
- # possible_answers.push(i.to_s)
- # i += 1
- # end
- # params[:question].each do |key,value|
- # answer = answer + value[:q_answer] + ","
- # blank_word = true if value[:q_part].blank? == true
- # blank_answer = true if value[:q_answer].blank? == true
- # answer_total += value[:q_answer].to_i
- # wrong_answer = true unless possible_answers.include?(value[:q_answer])
- # end
- #
- # error_messages = @question.make(params[:q_category], params[:q_subcategory], params[:q_summary],"Sequence",params[:q_text],answer,params[:q_weight])
- # error_messages = "" if error_messages == true
- # error_messages += "Error: Must write in all word boxes.<br>" if blank_word == true
- # error_messages += "Error: Must write in all answer boxes.<br>" if blank_answer == true
- # error_messages += "Error: One of your answers was outside the valid range.<br>" if wrong_answer == true
- # error_messages += "Error: Your answers do not add up to the right amount.<br>" if right_answer_total != answer_total
- #
- # if error_messages.blank?
- # params[:question].each do |key,value|
- # @question.add_choice(value[:q_part])
- # end
- # else
- # flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- # redirect_to :action=>'main_form', :parts=>params[:parts]
- # return
- # end
- #
- #
- #
- # when "True False"
- # #make question, storing error messages in a string
- # error_messages = @question.make(params[:q_category],params[:q_subcategory],params[:q_summary],"True False",params[:q_text],params[:q_asw],params[:q_weight])
- # #clear error messages if question.make returned true
- # error_messages = "" if error_messages == true
- # #display error messages if they exist
- # unless error_messages.blank?
- # flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- # render :partial=>'truefalse', :layout=>true #refresh the page
- # return #do not continue
- # end
- # #add the choices to the question so it displays properly to the student
- # @question.add_choice("True")
- # @question.add_choice("False")
- #
- #
- #
- # when "Multiple Short Answer"
- # answer = ""
- # blank_word = false
- # params[:question].each do |key,value|
- # answer = answer + value[:q_answer] + "," #create answer string for question making
- # blank_word = true if value[:q_answer].blank? #check if answer box is blank
- # blank_word = true if value[:q_part].blank? #check if question part text is blank
- # end
- # error_messages = @question.make(params[:q_category], params[:q_subcategory], params[:q_summary], "Multiple Short Answer", params[:q_text], answer, params[:weight])
- # error_messages = "" if error_messages == true
- # error_messages += "Error: Please enter text into all of the question and answer boxes." if blank_word == true
- # #add choices if error messages are blank
- # if error_messages.blank?
- # params[:question].each do |key,value|
- # @question.add_choice(value[:q_part])
- # end
- # else #display error messages if they exist
- # flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- # redirect_to :action=>'main_form', :parts=>params[:parts]
- # return
- # end
- #
- #
- #
- #
- #
- # when "Arrange Order"
- # answer = ""
- # params[:question].each do |key,value|
- # answer = answer + value[:q_answer] + ","
- # end
- #
- # error_messages = @question.make(params[:q_category], params[:q_subcategory], params[:q_summary], "Arrange Order", params[:q_text], answer, params[:weight])
- # error_messages = "" if error_messages == true
- # blank_word == false
- # params[:question].each do |key,value|
- # blank_word = true if value[:q_part].blank?
- # end
- # params[:question].each do |key,value|
- # blank_word = true if value[:q_answer].blank?
- # end
- # if(blank_word)
- # error_messages = error_messages + "Error: You must enter text in all of the boxes. Please review your question text and answers.<br>"
- # end
- # unless error_messages.blank?
- # flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- # redirect_to :action=>'main_form', :choices=>params[:parts]
- # return
- # end
- #
- # params[:question].each do |key,value|
- # @question.add_choice(value[:q_part])
- # end
- #
- #
- #
- #
- # when "Select Wrong Word"
- # #make question and store error messages in error_messages string
- # error_messages = @question.make(params[:q_category], params[:q_subcategory], params[:q_summary],"Select Wrong Word",params[:q_text],params[:q_asw],params[:q_weight])
- # #clear error_messages if question.make returns true
- # error_messages = "" if error_messages == true
- # blank_word = false
- # #check all option boxes are written in
- # params[:question].each do |key,value|
- # blank_word = true if value[:q_option].blank?
- # end
- # if(blank_word == true)
- # error_messages = error_messages + "Error: You must write in all of the option boxes.<br>"
- # end
- # #display the error messages if they exist
- # unless error_messages.blank?
- # flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- # options = params[:q_options]
- # redirect_to(:action=>'main_form', :choices=>options) # refresh the page so the error messages show
- # return
- # else #otherwise, add all the choices to the question and continue
- # params[:question].each do |key,value|
- # @question.add_choice(value[:q_option])
- # end
- # end
- #
- # when "Arrange Alphabetical"
- # answer = ""
- # #create answer string to use when making question
- # params[:question].each do |key,value|
- # answer = answer + value[:q_answer] + ","
- # end
- # error_messages = @question.make(params[:q_category], params[:q_subcategory], params[:q_summary],"Arrange Alphabetical",params[:q_text],answer,params[:q_weight])
- # error_messages = "" if error_messages == true
- # #check all option boxes are written in
- # blank_word = false
- # params[:question].each do |key,value|
- # blank_word = true if value[:q_part].blank?
- # end
- # error_messages += "Error: Please write in all option boxes.<br>" if blank_word == true
- # #check all answer boxes are written in
- # blank_answer = false
- # params[:question].each do |key,value|
- # blank_answer == true if value[:q_answer].blank?
- # end
- # error_messages += "Error: Please write in all answer boxes.<br>" if blank_answer == true
- # #check answers add up to the right total
- # right_total = 0
- # i = 1
- # while i <= params[:options].to_i
- # right_total += i
- # i += 1
- # end
- # q_ans_total = 0
- # params[:question].each do |key,value|
- # q_ans_total += value[:q_answer].to_i
- # end
- # if q_ans_total != right_total
- # error_messages += "Error: Your answers do not add up to the right total. Please review your answers.<br>"
- # end
- # #check all answers are in the correct range
- # correct_range = Array.new
- # i = 1
- # while i <= params[:options].to_i
- # correct_range.push(i.to_s)
- # i += 1
- # end
- # wrong_value = false
- # params[:question].each do |key,value|
- # wrong_value = true unless correct_range.include?(value[:q_answer])
- # end
- # error_messages += "Error: At least one of your answers is outside the valid range.<br>" if wrong_value == true
- # #display error messages unless they are blank
- # unless error_messages.blank?
- # flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- # options = params[:options]
- # redirect_to(:action=>'main_form', :parts=>options) # refresh the page so the error messages show
- # return
- # else #if error messages are blank, add all options to the question and continue (will be saved at end of method)
- # params[:question].each do |key,value|
- # @question.add_choice(value[:q_part])
- # end
- # end
- #
- #
- # when "Word Match" #to create a question of type "Word Match"
- # answer = ""
- # #create answer string to use when making question
- # params[:question].each do |key,value|
- # answer = answer + value[:answer].to_s + ","
- # end
- # error_messages = "" #clear error messages
- # error_messages = @question.make(params[:q_category], params[:q_subcategory], params[:q_summary], "Word Match", params[:q_text], answer, params[:q_weight])
- # error_messages = "" if error_messages == true
- # #check if all word and match boxes are filled
- # blank_word = false
- # params[:question].each do |key,value|
- # blank_word = true if value[:word].blank? || value[:match].blank?
- # end
- # if blank_word
- # error_messages = error_messages + "Error: You have at least one blank word box. Please enter something into every word box.<br>"
- # end
- # # set up valid answers
- # # what should the answers add up to
- # answer_invalid = false
- # right_total = 0
- # total = 0
- # i = 1
- # while i <= params[:options].to_i
- # right_total = right_total + i
- # i = i + 1
- # end
- # # what are all the correct possible answers
- # possible_answers = Array.new()
- # i = 1
- # while i <= params[:options].to_i
- # possible_answers.push(i.to_s)
- # i = i+1
- # end
- # #add up all the answers to check if they are all there,
- # #and also check if they are a valid number
- # params[:question].each do |key,value|
- # total = total + value[:answer].to_i
- # unless possible_answers.include?(value[:answer].to_s)
- # answer_invalid = true
- # end
- # end
- # if total != right_total
- # answer_invalid = true
- # end
- # if answer_invalid
- # error_messages = error_messages + "Error: Answers invalid. Please review your answers in the \"Matches to Number\" column."
- # end
- #
- # flash[:error] = "" #clear error messages
- # #display error messages if they exist
- # unless error_messages.blank? || error_messages == true #when there are error messages and question making was unsuccessful
- # flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>" #put error messages on the page
- # #@blah = Question.new(:q_summary=>params[:q_summary]) # save the text the user has already entered
- # #render(:action=>'create_wordmatch', :object=>@blah) # refresh the page so the error messages show
- # options = params[:options]
- # redirect_to(:action=>'main_form', :choices=>options) # refresh the page so the error messages show
- # return #do not continue making the question if errors are found
- #
- # else #if no errors, add the choices to the question
- # params[:question].each do |key,value|
- # @question.add_choice(value[:word], "word")
- # end
- # params[:question].each do |key,value|
- # @question.add_choice(value[:match], "match")
- # end
- # end
- #
- # when "Calculation"
- # answer = ""
- # #create answer string to use when creating question
- # params[:question].each do |key,value|
- # answer = answer + value[:q_answer] + ","
- # end
- # # make question and store error messages
- # error_messages = @question.make(params[:q_category], params[:q_subcategory], params[:q_summary], "Calculation", params[:q_text], answer, params[:weight])
- # # if question.make is true (successful), clear the error messages
- # error_messages = "" if error_messages == true
- # blank_word == false
- # #check if the user left any word boxes blank
- # params[:question].each do |key,value|
- # blank_word = true if value[:q_part].blank?
- # end
- # params[:question].each do |key,value|
- # blank_word = true if value[:q_answer].blank?
- # end
- # if(blank_word)
- # error_messages = error_messages + "Error: You must enter text in all of the boxes. Please review your question text and answers.<br>"
- # end
- #
- # flash[:error] == ""
- # #display the error messages unless they are blank
- # unless error_messages.blank?
- # flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- # options = params[:parts]
- # redirect_to(:action => 'main_form', :parts=>options)
- # return
- # #if there are no error messages, add all the question choices to the question and continue
- # #(question will be saved at the end of this method)
- # else
- # params[:question].each do |key,value|
- # @question.add_choice(value[:q_part])
- # end
- # end
- #
- # when "Fill in Blanks"
- # answer = ""
- # #create the answer string to be used when making the question later
- # params[:question].each do |key,value|
- # answer = answer + value[:q_blank] + ","
- # end
- #
- # blanks = params[:q_text].scan('%%%') #array of '%%%' is stored in blanks
- # error_messages = ""
- # if blanks.size != (params[:q_amount].to_i)
- # error_messages += "Error: You have the wrong number of blank spaces in your question text. Please enter %%% instead of the word anywhere you want a blank to be.<br>"
- # end
- # #create question and store errors in make_errors string
- # make_errors = @question.make(params[:q_category], params[:q_subcategory], params[:q_summary], "Fill in Blanks", params[:q_text] + " ", answer,params[:weight])
- # error_messages += make_errors unless make_errors == true
- #
- # #check all word boxes have text
- # blank_word = false
- # params[:question].each do |key,value|
- # blank_word = true if value[:q_blank].blank?
- # end
- # error_messages += "Error: Please enter a word into all of the blank word boxes.<br>" if blank_word == true
- #
- # #display messages if error messages exist
- # unless error_messages.blank?
- # flash[:error] = "<h1><font color=red>" + error_messages + "</font></h1>"
- # options = params[:q_amount]
- # redirect_to(:action => 'main_form', :parts=>options)
- # return #do not continue processing (this means question will not be saved)
- # end
- #
- #
- # when "Multipart"
- # @question.q_data = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
- # <question category=\"Literacy\" subcategory=\"Multipart\">
- # <qtype>Multipart</qtype>
- # <qtext>" + params[:q_text] + "</qtext>
- # <qsummary>" + params[:q_summary] + "</qsummary>
- # </question>"
- # @question.make(params[:q_category], params[:q_subcategory], params[:q_summarry], "Multipart")
Add Comment
Please, Sign In to add comment