Skip to content

Instantly share code, notes, and snippets.

@kracekumar
Created May 14, 2011 15:43
Show Gist options
  • Save kracekumar/972334 to your computer and use it in GitHub Desktop.
Save kracekumar/972334 to your computer and use it in GitHub Desktop.
exam_group_error
Exam Columns (0.7ms) SHOW FIELDS FROM `exams`
Subject Load (0.1ms) SELECT * FROM `subjects` WHERE (`subjects`.`id` = 11 AND (`subjects`.`is_deleted` = 0))
ActionView::TemplateError (undefined method `_delete' for #<Exam:0xb6c53be8>) on line #69 of app/views/exam/_exam_marks_form.rhtml:
66: <td class="col-1">
67: <div class="label-field-pair2">
68: <div class="text-input-bg2">
69: <%= exam_form.check_box :_delete %>
70: </div>
71: </div>
72: </td>
app/views/exam/_exam_marks_form.rhtml:69:in `_run_rhtml_app47views47exam47_exam_marks_form46rhtml_locals_exam_marks_form_object'
searchlogic (2.5.5) lib/searchlogic/rails_helpers.rb:79:in `fields_for'
app/views/exam/_exam_marks_form.rhtml:36:in `_run_rhtml_app47views47exam47_exam_marks_form46rhtml_locals_exam_marks_form_object'
searchlogic (2.5.5) lib/searchlogic/rails_helpers.rb:79:in `fields_for'
searchlogic (2.5.5) lib/searchlogic/rails_helpers.rb:64:in `form_for'
app/views/exam/_exam_marks_form.rhtml:1:in `_run_rhtml_app47views47exam47_exam_marks_form46rhtml_locals_exam_marks_form_object'
app/controllers/exam_controller.rb:28:in `update_exam_form'
app/controllers/exam_controller.rb:27:in `update_exam_form'
/usr/lib/ruby/1.8/mongrel.rb:159:in `process_client'
/usr/lib/ruby/1.8/mongrel.rb:158:in `each'
/usr/lib/ruby/1.8/mongrel.rb:158:in `process_client'
/usr/lib/ruby/1.8/mongrel.rb:285:in `run'
/usr/lib/ruby/1.8/mongrel.rb:285:in `initialize'
/usr/lib/ruby/1.8/mongrel.rb:285:in `new'
/usr/lib/ruby/1.8/mongrel.rb:285:in `run'
/usr/lib/ruby/1.8/mongrel.rb:268:in `initialize'
/usr/lib/ruby/1.8/mongrel.rb:268:in `new'
/usr/lib/ruby/1.8/mongrel.rb:268:in `run'
Rendered rescues/_trace (55.7ms)
Rendered rescues/_request_and_response (0.4ms)
Rendering rescues/layout
(internal_server_error)
#exam_group_controller.rb
class ExamController < ApplicationController
before_filter :login_required
before_filter :protect_other_student_data
filter_access_to :all
def index
end
def update_exam_form
@batch = Batch.find(params[:batch])
@name = params[:exam_option][:name]
@type = params[:exam_option][:exam_type]
unless @name == ''
@exam_group = ExamGroup.new
@normal_subjects = Subject.find_all_by_batch_id(@batch.id,:conditions=>"no_exams = false AND elective_group_id IS NULL AND is_deleted = false")
@elective_subjects = []
elective_subjects = Subject.find_all_by_batch_id(@batch.id,:conditions=>"no_exams = false AND elective_group_id IS NOT NULL AND is_deleted = false")
elective_subjects.each do |e|
is_assigned = StudentsSubject.find_all_by_subject_id(e.id)
unless is_assigned.empty?
@elective_subjects.push e
end
end
@all_subjects = @normal_subjects+@elective_subjects
@all_subjects.each { |subject| @exam_group.exams.build(:subject_id => subject.id) }
if @type == 'Marks' or @type == 'MarksAndGrades'
render(:update) do |page|
page.replace_html 'exam-form', :partial=>'exam_marks_form'
page.replace_html 'flash', :text=>''
end
else
render(:update) do |page|
page.replace_html 'exam-form', :partial=>'exam_grade_form'
page.replace_html 'flash', :text=>''
end
end
else
render(:update) do |page|
page.replace_html 'flash', :text=>'<div class="errorExplanation"><p>Exam name can\'t be blank</p></div>'
end
end
end
def publish
@exam_group = ExamGroup.find(params[:id])
@exams = @exam_group.exams
@batch = @exam_group.batch
@sms_setting_notice = ""
@no_exam_notice = ""
if params[:status] == "schedule"
students = @batch.students
students.each do |s|
student_user = s.user
Reminder.create(:sender=> current_user.id,:recipient=>student_user.id,
:subject=>"Exam Scheduled",
:body=>"#{@exam_group.name} has been scheduled <br/> Please view calendar for more details")
end
end
unless @exams.empty?
ExamGroup.update(@exam_group.id,:is_published=>true) if params[:status] == "schedule"
ExamGroup.update(@exam_group.id,:result_published=>true) if params[:status] == "result"
sms_setting = SmsSetting.new()
if sms_setting.application_sms_active and sms_setting.exam_result_schedule_sms_active
students = @batch.students
students.each do |s|
guardian = s.immediate_contact
recipients = []
if s.is_sms_enabled
if sms_setting.student_sms_active
recipients.push s.phone2 unless s.phone2.nil?
end
if sms_setting.parent_sms_active
unless guardian.nil?
recipients.push guardian.mobile_phone unless guardian.mobile_phone.nil?
end
end
@message = "#{@exam_group.name} exam Timetable has been published." if params[:status] == "schedule"
@message = "#{@exam_group.name} exam result has been published." if params[:status] == "result"
unless recipients.empty?
sms = SmsManager.new(@message,recipients)
sms.send_sms
end
end
end
else
@conf = Configuration.available_modules
if @conf.include?('SMS')
@sms_setting_notice = "Exam schedule published, No sms was sent as Sms setting was not activated" if params[:status] == "schedule"
@sms_setting_notice = "Exam result published, No sms was sent as Sms setting was not activated" if params[:status] == "result"
else
@sms_setting_notice = "Exam schedule published" if params[:status] == "schedule"
@sms_setting_notice = "Exam result published" if params[:status] == "result"
end
end
if params[:status] == "result"
students = @batch.students
students.each do |s|
student_user = s.user
Reminder.create(:sender=> current_user.id,:recipient=>student_user.id,
:subject=>"Result Published",
:body=>"#{@exam_group.name} result has been published <br/> Please view reports for your result")
end
end
else
@no_exam_notice = "Exam scheduling not done yet."
end
end
def grouping
@batch = Batch.find(params[:id])
@exam_groups = ExamGroup.find_all_by_batch_id(@batch.id)
if request.post?
unless params[:exam_grouping].nil?
unless params[:exam_grouping][:exam_group_ids].nil?
GroupedExam.delete_all(:batch_id=>@batch.id)
exam_group_ids = params[:exam_grouping][:exam_group_ids]
exam_group_ids.each do |e|
GroupedExam.create(:exam_group_id=>e,:batch_id=>@batch.id)
end
end
else
GroupedExam.delete_all(:batch_id=>@batch.id)
end
flash[:notice]="Selected exams grouped successfully."
end
end
#REPORTS
def exam_wise_report
@batches = Batch.active
@exam_groups = []
end
def list_exam_types
batch = Batch.find(params[:batch_id])
@exam_groups = ExamGroup.find_all_by_batch_id(batch.id)
render(:update) do |page|
page.replace_html 'exam-group-select', :partial=>'exam_group_select'
end
end
def generated_report
if params[:student].nil?
if params[:exam_report].nil? or params[:exam_report][:exam_group_id].empty?
flash[:notice] = "Select a batch and exam to continue."
redirect_to :action=>'exam_wise_report' and return
end
else
if params[:exam_group].nil?
flash[:notice] = "Invalid parameters."
redirect_to :action=>'exam_wise_report' and return
end
end
if params[:student].nil?
@exam_group = ExamGroup.find(params[:exam_report][:exam_group_id])
@batch = @exam_group.batch
@student = @batch.students.first
general_subjects = Subject.find_all_by_batch_id(@batch.id, :conditions=>"elective_group_id IS NULL")
student_electives = StudentsSubject.find_all_by_student_id(@student.id,:conditions=>"batch_id = #{@batch.id}")
elective_subjects = []
student_electives.each do |elect|
elective_subjects.push Subject.find(elect.subject_id)
end
@subjects = general_subjects + elective_subjects
@exams = []
@subjects.each do |sub|
exam = Exam.find_by_exam_group_id_and_subject_id(@exam_group.id,sub.id)
@exams.push exam unless exam.nil?
end
@graph = open_flash_chart_object(770, 350,
"/exam/graph_for_generated_report?batch=#{@student.batch.id}&examgroup=#{@exam_group.id}&student=#{@student.id}")
else
@exam_group = ExamGroup.find(params[:exam_group])
@student = Student.find(params[:student])
@batch = @student.batch
general_subjects = Subject.find_all_by_batch_id(@student.batch.id, :conditions=>"elective_group_id IS NULL")
student_electives = StudentsSubject.find_all_by_student_id(@student.id,:conditions=>"batch_id = #{@student.batch.id}")
elective_subjects = []
student_electives.each do |elect|
elective_subjects.push Subject.find(elect.subject_id)
end
@subjects = general_subjects + elective_subjects
@exams = []
@subjects.each do |sub|
exam = Exam.find_by_exam_group_id_and_subject_id(@exam_group.id,sub.id)
@exams.push exam unless exam.nil?
end
@graph = open_flash_chart_object(770, 350,
"/exam/graph_for_generated_report?batch=#{@student.batch.id}&examgroup=#{@exam_group.id}&student=#{@student.id}")
end
end
def generated_report_pdf
@config = Configuration.get_config_value('InstitutionName')
@exam_group = ExamGroup.find(params[:exam_group])
@batch = Batch.find(params[:batch])
@students = @batch.students
respond_to do |format|
format.pdf { render :layout => false }
end
end
def consolidated_exam_report
@exam_group = ExamGroup.find(params[:exam_group])
end
def consolidated_exam_report_pdf
@exam_group = ExamGroup.find(params[:exam_group])
respond_to do |format|
format.pdf { render :layout => false }
end
end
def subject_wise_report
@batches = Batch.active
@subjects = []
end
def list_subjects
@subjects = Subject.find_all_by_batch_id(params[:batch_id],:conditions=>"is_deleted=false")
render(:update) do |page|
page.replace_html 'subject-select', :partial=>'subject_select'
end
end
def generated_report2
#subject-wise-report-for-batch
unless params[:exam_report][:subject_id] == ""
@subject = Subject.find(params[:exam_report][:subject_id])
@batch = @subject.batch
@students = @batch.students
@exam_groups = ExamGroup.find(:all,:conditions=>{:batch_id=>@batch.id})
else
flash[:notice] = "select a subject to continue"
redirect_to :action=>'subject_wise_report'
end
end
def generated_report2_pdf
#subject-wise-report-for-batch
@subject = Subject.find(params[:subject_id])
@batch = @subject.batch
@students = @batch.students
@exam_groups = ExamGroup.find(:all,:conditions=>{:batch_id=>@batch.id})
respond_to do |format|
format.pdf { render :layout => false }
end
end
def generated_report3
#student-subject-wise-report
@student = Student.find(params[:student])
@batch = @student.batch
@subject = Subject.find(params[:subject])
@exam_groups = ExamGroup.find(:all,:conditions=>{:batch_id=>@batch.id})
@graph = open_flash_chart_object(770, 350,
"/exam/graph_for_generated_report3?subject=#{@subject.id}&student=#{@student.id}")
end
def final_report_type
batch = Batch.find(params[:batch_id])
@grouped_exams = GroupedExam.find_all_by_batch_id(batch.id)
render(:update) do |page|
page.replace_html 'report_type',:partial=>'report_type'
end
end
def generated_report4
if params[:student].nil?
if params[:exam_report].nil? or params[:exam_report][:batch_id].empty?
flash[:notice] = "Select a batch to continue"
redirect_to :action=>'grouped_exam_report' and return
end
else
if params[:type].nil?
flash[:notice] = "Invalid parameters."
redirect_to :action=>'grouped_exam_report' and return
end
end
#grouped-exam-report-for-batch
if params[:student].nil?
@type = params[:type]
@batch = Batch.find(params[:exam_report][:batch_id])
@student = @batch.students.first
if @type == 'grouped'
@grouped_exams = GroupedExam.find_all_by_batch_id(@batch.id)
@exam_groups = []
@grouped_exams.each do |x|
@exam_groups.push ExamGroup.find(x.exam_group_id)
end
else
@exam_groups = ExamGroup.find_all_by_batch_id(@batch.id)
end
general_subjects = Subject.find_all_by_batch_id(@batch.id, :conditions=>"elective_group_id IS NULL AND is_deleted=false")
student_electives = StudentsSubject.find_all_by_student_id(@student.id,:conditions=>"batch_id = #{@batch.id}")
elective_subjects = []
student_electives.each do |elect|
elective_subjects.push Subject.find(elect.subject_id)
end
@subjects = general_subjects + elective_subjects
else
@student = Student.find(params[:student])
@batch = @student.batch
@type = params[:type]
if params[:type] == 'grouped'
@grouped_exams = GroupedExam.find_all_by_batch_id(@batch.id)
@exam_groups = []
@grouped_exams.each do |x|
@exam_groups.push ExamGroup.find(x.exam_group_id)
end
else
@exam_groups = ExamGroup.find_all_by_batch_id(@batch.id)
end
general_subjects = Subject.find_all_by_batch_id(@student.batch.id, :conditions=>"elective_group_id IS NULL AND is_deleted=false")
student_electives = StudentsSubject.find_all_by_student_id(@student.id,:conditions=>"batch_id = #{@student.batch.id}")
elective_subjects = []
student_electives.each do |elect|
elective_subjects.push Subject.find(elect.subject_id)
end
@subjects = general_subjects + elective_subjects
end
end
def generated_report4_pdf
#grouped-exam-report-for-batch
if params[:student].nil?
@type = params[:type]
@batch = Batch.find(params[:exam_report][:batch_id])
@student = @batch.students.first
if @type == 'grouped'
@grouped_exams = GroupedExam.find_all_by_batch_id(@batch.id)
@exam_groups = []
@grouped_exams.each do |x|
@exam_groups.push ExamGroup.find(x.exam_group_id)
end
else
@exam_groups = ExamGroup.find_all_by_batch_id(@batch.id)
end
general_subjects = Subject.find_all_by_batch_id(@batch.id, :conditions=>"elective_group_id IS NULL")
student_electives = StudentsSubject.find_all_by_student_id(@student.id,:conditions=>"batch_id = #{@batch.id}")
elective_subjects = []
student_electives.each do |elect|
elective_subjects.push Subject.find(elect.subject_id)
end
@subjects = general_subjects + elective_subjects
else
@student = Student.find(params[:student])
@batch = @student.batch
@type = params[:type]
if params[:type] == 'grouped'
@grouped_exams = GroupedExam.find_all_by_batch_id(@batch.id)
@exam_groups = []
@grouped_exams.each do |x|
@exam_groups.push ExamGroup.find(x.exam_group_id)
end
else
@exam_groups = ExamGroup.find_all_by_batch_id(@batch.id)
end
general_subjects = Subject.find_all_by_batch_id(@student.batch.id, :conditions=>"elective_group_id IS NULL")
student_electives = StudentsSubject.find_all_by_student_id(@student.id,:conditions=>"batch_id = #{@student.batch.id}")
elective_subjects = []
student_electives.each do |elect|
elective_subjects.push Subject.find(elect.subject_id)
end
@subjects = general_subjects + elective_subjects
end
respond_to do |format|
format.pdf { render :layout => false }
end
end
def previous_years_marks_overview
@student = Student.find(params[:student])
@all_batches = @student.all_batches
@graph = open_flash_chart_object(770, 350,
"/exam/graph_for_previous_years_marks_overview?student=#{params[:student]}&graphtype=#{params[:graphtype]}")
respond_to do |format|
format.pdf { render :layout => false }
format.html
end
end
def academic_report
#academic-archived-report
@student = Student.find(params[:student])
@batch = Batch.find(params[:year])
if params[:type] == 'grouped'
@grouped_exams = GroupedExam.find_all_by_batch_id(@batch.id)
@exam_groups = []
@grouped_exams.each do |x|
@exam_groups.push ExamGroup.find(x.exam_group_id)
end
else
@exam_groups = ExamGroup.find_all_by_batch_id(@batch.id)
end
general_subjects = Subject.find_all_by_batch_id(@batch.id, :conditions=>"elective_group_id IS NULL and is_deleted=false")
student_electives = StudentsSubject.find_all_by_student_id(@student.id,:conditions=>"batch_id = #{@batch.id}")
elective_subjects = []
student_electives.each do |elect|
elective_subjects.push Subject.find(elect.subject_id)
end
@subjects = general_subjects + elective_subjects
end
def create_exam
@course= Course.active
end
def update_batch_ex_result
@batch = Batch.find_all_by_course_id(params[:course_name], :conditions => { :is_deleted => false, :is_active => true })
render(:update) do |page|
page.replace_html 'update_batch', :partial=>'update_batch_ex_result'
end
end
def update_batch
@batch = Batch.find_all_by_course_id(params[:course_name], :conditions => { :is_deleted => false, :is_active => true })
render(:update) do |page|
page.replace_html 'update_batch', :partial=>'update_batch'
end
end
#GRAPHS
def graph_for_generated_report
student = Student.find(params[:student])
examgroup = ExamGroup.find(params[:examgroup])
batch = student.batch
general_subjects = Subject.find_all_by_batch_id(batch.id, :conditions=>"elective_group_id IS NULL")
student_electives = StudentsSubject.find_all_by_student_id(student.id,:conditions=>"batch_id = #{batch.id}")
elective_subjects = []
student_electives.each do |elect|
elective_subjects.push Subject.find(elect.subject_id)
end
subjects = general_subjects + elective_subjects
x_labels = []
data = []
data2 = []
subjects.each do |s|
exam = Exam.find_by_exam_group_id_and_subject_id(examgroup.id,s.id)
res = ExamScore.find_by_exam_id_and_student_id(exam, student)
unless res.nil?
x_labels << s.code
data << res.marks
data2 << exam.class_average_marks
end
end
bargraph = BarFilled.new()
bargraph.width = 1;
bargraph.colour = '#bb0000';
bargraph.dot_size = 5;
bargraph.text = "Student's marks"
bargraph.values = data
bargraph2 = BarFilled.new
bargraph2.width = 1;
bargraph2.colour = '#5E4725';
bargraph2.dot_size = 5;
bargraph2.text = "Class average"
bargraph2.values = data2
x_axis = XAxis.new
x_axis.labels = x_labels
y_axis = YAxis.new
y_axis.set_range(0,100,20)
title = Title.new(student.full_name)
x_legend = XLegend.new("Subjects")
x_legend.set_style('{font-size: 14px; color: #778877}')
y_legend = YLegend.new("Marks")
y_legend.set_style('{font-size: 14px; color: #770077}')
chart = OpenFlashChart.new
chart.set_title(title)
chart.y_axis = y_axis
chart.x_axis = x_axis
chart.y_legend = y_legend
chart.x_legend = x_legend
chart.add_element(bargraph)
chart.add_element(bargraph2)
render :text => chart.render
end
def graph_for_generated_report3
student = Student.find params[:student]
subject = Subject.find params[:subject]
exams = Exam.find_all_by_subject_id(subject.id, :order => 'start_time asc')
data = []
x_labels = []
exams.each do |e|
exam_result = ExamScore.find_by_exam_id_and_student_id(e, student.id)
unless exam_result.nil?
data << exam_result.marks
x_labels << XAxisLabel.new(exam_result.exam.exam_group.name, '#000000', 10, 0)
end
end
x_axis = XAxis.new
x_axis.labels = x_labels
line = BarFilled.new
line.width = 1
line.colour = '#5E4725'
line.dot_size = 5
line.values = data
y = YAxis.new
y.set_range(0,100,20)
title = Title.new(subject.name)
x_legend = XLegend.new("Examination name")
x_legend.set_style('{font-size: 14px; color: #778877}')
y_legend = YLegend.new("Marks")
y_legend.set_style('{font-size: 14px; color: #770077}')
chart = OpenFlashChart.new
chart.set_title(title)
chart.set_x_legend(x_legend)
chart.set_y_legend(y_legend)
chart.y_axis = y
chart.x_axis = x_axis
chart.add_element(line)
render :text => chart.to_s
end
def graph_for_previous_years_marks_overview
student = Student.find(params[:student])
x_labels = []
data = []
student.all_batches.each do |b|
x_labels << b.name
exam = ExamScore.new()
data << exam.batch_wise_aggregate(student,b)
end
if params[:graphtype] == 'Line'
line = Line.new
else
line = BarFilled.new
end
line.width = 1; line.colour = '#5E4725'; line.dot_size = 5; line.values = data
x_axis = XAxis.new
x_axis.labels = x_labels
y_axis = YAxis.new
y_axis.set_range(0,100,20)
title = Title.new(student.full_name)
x_legend = XLegend.new("Academic year")
x_legend.set_style('{font-size: 14px; color: #778877}')
y_legend = YLegend.new("Total marks")
y_legend.set_style('{font-size: 14px; color: #770077}')
chart = OpenFlashChart.new
chart.set_title(title)
chart.y_axis = y_axis
chart.x_axis = x_axis
chart.add_element(line)
render :text => chart.to_s
end
end
#new.html.erb
<div id="content-header">
<img src="/images/examination/show_exam.png" alt="Exam" />
<h1>Exams</h1>
<h3>New Exam</h3>
<div id="app-back-button">
<%= link_to_function image_tag("/images/buttons/back.png",:border => 0), "history.back()" %>
</div>
</div>
<div id="page-yield">
<% unless flash[:notice].nil? %>
<p class="flash-msg"> <%= flash[:notice] %> </p>
<% end %>
<div class="bread_crumb">
<%= link_to 'Courses', courses_path %> &raquo;
<%= link_to @course.full_name, @course %> &raquo;
<%= link_to "Batch #{@batch.name}", [@course, @batch] %> &raquo;
<%= link_to "Exams", batch_exam_groups_path(@batch) %> &raquo;
New Exam
</div>
<div class="box">
<div id="flash"></div>
<div id="exam-form">
<%= error_messages_for :exam_group %>
<% form_remote_for :exam_option, :url => {:controller=>'exam',:action => 'update_exam_form',:batch=>@batch} do |form| %>
<div class="label-field-pair">
<label for="exam_name">Name</label>
<% if params[:ename].nil? %>
<% @ename = "" %>
<% else %>
<% @ename = params[:ename] %>
<% end %>
<div class="text-input-bg"><%= form.text_field :name, :value=>@ename%></div>
</div>
<div class="label-field-pair">
<label for="exam_type">Exam Type</label>
<div class="text-input-bg"><%= select :exam_option,:exam_type,['Marks','Grades','MarksAndGrades'] %></div>
</div>
<%= submit_tag "", :value => "► Save", :class => "submit_button" %>
<% # form.submit("Save") %>
<%end%>
</div>
<div class="extender"></div>
</div></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment