osem-fcy/app/controllers/admin/registrations_controller.rb

49 lines
2.3 KiB
Ruby
Raw Normal View History

2013-01-07 09:04:09 +01:00
class Admin::RegistrationsController < ApplicationController
before_filter :verify_organizer
def show
session[:return_to] ||= request.referer
@pdf_filename = "#{@conference.title}.pdf"
@registrations = @conference.registrations.all(:joins => :person,
2013-07-12 10:45:40 +03:00
:order => "registrations.created_at ASC",
2013-01-07 09:04:09 +01:00
:select => "registrations.*,
people.last_name AS last_name,
people.first_name AS first_name,
people.public_name AS public_name,
people.email AS email")
2013-07-12 10:45:40 +03:00
@attended = @conference.registrations.where("attended = ?", true)
@headers = %w[attended name email social_events attending_with_partner need_access other_needs arrival departure]
end
def change_field
@registration = Registration.find(params[:id])
field = params[:view_field]
if @registration.send(field.to_sym)
@registration.update_attribute(:"#{field}",0)
else
@registration.update_attribute(:"#{field}",1)
end
redirect_to admin_conference_registrations_path(@conference.short_title, @registration)
flash[:notice] = "Updated '#{params[:view_field]}' for #{(Person.where("id = ?", @registration.person_id).first).email}"
2013-01-07 09:04:09 +01:00
end
2013-07-12 10:54:59 +03:00
def delete
if has_role?(current_user, "Admin")
registration = @conference.registrations.where(:id => params[:id]).first
person = Person.where("id = ?", registration.person_id).first
2013-07-12 10:54:59 +03:00
begin registration.destroy
redirect_to admin_conference_registrations_path
flash[:notice] = "Deleted registration for #{person.public_name} #{person.email}"
rescue Exception => e
Rails.logger.debug e.backtrace.join("\n")
redirect_to(admin_conference_registrations_path(@conference.short_title), :alert => 'Failed to delete registration:' + e.message)
return
end
else
redirect_to(admin_conference_registrations_path(@conference.short_title), :alert => 'You must be an admin to delete a registration.')
2013-07-12 10:54:59 +03:00
end
end
2013-01-07 09:04:09 +01:00
end