Commit 160094e1 authored by Mario Manno's avatar Mario Manno

update some AR query related code

parent 7b80a7f1
......@@ -9,7 +9,7 @@ class Cfp::EventsController < ApplicationController
def index
authorize! :submit, Event
@events = current_user.person.events.all
@events = current_user.person.events
unless @events.nil?
@events.map { |event| event.clean_event_attributes! }
end
......@@ -69,7 +69,7 @@ class Cfp::EventsController < ApplicationController
# PUT /cfp/events/1.xml
def update
authorize! :submit, Event
@event = current_user.person.events.find(params[:id], readonly: false)
@event = current_user.person.events.readonly(false).find(params[:id])
params[:event].delete('recording_license')
@event.recording_license = @event.conference.default_recording_license unless @event.recording_license
if @event.accepted?
......
......@@ -28,14 +28,14 @@ class Public::ScheduleController < ApplicationController
end
@day = @conference.days[@day_index]
@all_rooms = @conference.rooms.is_public.all
@rooms = Array.new
@events = Hash.new
@skip_row = Hash.new
@all_rooms = @conference.rooms.is_public
@rooms = []
@events = {}
@skip_row = {}
@all_rooms.each do |room|
events = room.events.confirmed.no_conflicts.is_public.scheduled_on(@day).order(:start_time).all
events = room.events.confirmed.no_conflicts.is_public.scheduled_on(@day).order(:start_time).to_a
unless events.empty?
@events[room] = events
@events[room] = events
@skip_row[room] = 0
@rooms << room
end
......@@ -48,7 +48,7 @@ class Public::ScheduleController < ApplicationController
format.html
format.pdf do
@page_size = "A4"
render template: "schedule/custom_pdf"
render template: "schedule/custom_pdf"
end
end
end
......
......@@ -39,9 +39,9 @@ class ScheduleController < ApplicationController
@page_size = params[:page_size]
@day = @conference.days.find(params[:date_id])
@rooms = @conference.rooms.is_public.find(params[:room_ids])
@events = Hash.new
@events = {}
@rooms.each do |room|
@events[room] = room.events.accepted.is_public.scheduled_on(@day).order(:start_time).all
@events[room] = room.events.accepted.is_public.scheduled_on(@day).order(:start_time)
end
respond_to do |format|
......
......@@ -30,7 +30,7 @@ class UsersController < ApplicationController
@user = @person.user
can_manage_user!
@user.conference_users.select! { |cu|
@user.conference_users.to_a.select! { |cu|
can? :assign_user_roles, cu.conference
}
end
......
......@@ -89,19 +89,19 @@ class Person < ActiveRecord::Base
def events_in(conference)
self.events.where(conference_id: conference.id).all
self.events.where(conference_id: conference.id)
end
def events_as_presenter_in(conference)
self.events.where(:"event_people.event_role" => ["speaker", "moderator"], conference_id: conference.id).all
self.events.where(:"event_people.event_role" => ["speaker", "moderator"], conference_id: conference.id)
end
def events_as_presenter_not_in(conference)
self.events.where(:"event_people.event_role" => ["speaker", "moderator"]).where("conference_id != ?", conference.id).all
self.events.where(:"event_people.event_role" => ["speaker", "moderator"]).where("conference_id != ?", conference.id)
end
def public_and_accepted_events_as_speaker_in(conference)
self.events.is_public.accepted.where(:"events.state" => :confirmed, :"event_people.event_role" => ["speaker", "moderator"], conference_id: conference.id).all
self.events.is_public.accepted.where(:"events.state" => :confirmed, :"event_people.event_role" => ["speaker", "moderator"], conference_id: conference.id)
end
def role_state(conference)
......
......@@ -118,7 +118,7 @@ class User < ActiveRecord::Base
end
def record_login!
update_attributes({last_sign_in_at: Time.now, sign_in_count: sign_in_count + 1}, without_protection: true)
update_attributes(last_sign_in_at: Time.now, sign_in_count: sign_in_count + 1)
end
private
......
......@@ -3,14 +3,14 @@ def info_table_rows(event)
room = event.room.try(:name) or ""
time_str = event.humanized_time_str
rows = []
rows << [event.track.try(:name), event.event_type,
rows << [event.track.try(:name), event.event_type,
event.language, format_time_slots(event.time_slots)]
rows << [room, time_str] if room.present? or time_str.present?
rows
end
def add_speakers(columns, event)
speakers = event.speakers.each do |p|
event.speakers.each do |p|
columns << {text: p.full_name + "\n", size: 12}
availabilities_in = p.availabilities_in(@conference)
......@@ -19,7 +19,7 @@ def add_speakers(columns, event)
columns << {text: "n/a #{l(d.start_date, format: :short_datetime)}\n", size: 9}
}
availabilities = availabilities_in.map { |a| a.humanized_date_range }
availabilities = availabilities_in.map { |a| a.humanized_date_range }
availabilities = availabilities - @conference_days
columns << {text: availabilities.join("\n")+"\n", size: 9}
end
......@@ -32,7 +32,7 @@ def add_event_rating(columns, event)
end
def abstract(event)
abstract = (event.abstract || event.description || "").gsub(/(\r\n|\n)/, " ")
(event.abstract || event.description || "").gsub(/(\r\n|\n)/, " ")
end
prawn_document(page_layout: :landscape) do |pdf|
......@@ -47,9 +47,10 @@ prawn_document(page_layout: :landscape) do |pdf|
pdf.define_grid(rows: 2, columns: 2, gutter: 10)
@conference_days = @conference.days.map { |day| day.humanized_date_range }
@events = @events.to_a
(@events.size / 4 + 1).times do
[[0,0],[0,1],[1,0],[1,1]].each do |coords|
if event = @events.pop
......@@ -99,7 +100,7 @@ prawn_document(page_layout: :landscape) do |pdf|
end
pdf.start_new_page unless @events.empty?
end
end
......@@ -18,8 +18,8 @@
= link_to @conference.title + " - Call for Papers", cfp_root_path, class: "brand"
- if current_user and current_user.person
%ul.nav.secondary-nav.pull-right
- conferences = Conference.creation_order.has_submission(current_user.person).all
- if conferences.count > 1
- conferences = Conference.creation_order.has_submission(current_user.person)
- if conferences.any?
%li.dropdown
= link_to t("switch_conference", default: "Switch conference"), "#", class: "dropdown-toggle"
%ul.dropdown-menu
......
......@@ -44,7 +44,7 @@ class ConferenceScrubber
def scrub_person(person)
# get a writable record
person = Person.find person
person = Person.find person.id
unless person.email_public or person.include_in_mailings
person.email = DUMMY_MAIL
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment