-
class Admin::FestivityCategoriesController < Admin::ResourceController
-
-
def index
-
-
end
-
-
def show
-
-
end
-
-
def create
-
category_type = FestivityCategoryType.find(params[:category_type_id])
-
-
if category_type.festivity_categories.new(name: params[:name], parent_id: params[:parent_id]).save
-
render partial: 'admin/sites/partials/new_category', :locals => { :category_type => category_type, :category_types => category_type.site.festivity_active_category_types}
-
else
-
render status: :conflict, text: "#{category_type.name} must be unique."
-
end
-
-
end
-
-
def destroy
-
category = FestivityCategory.find(params[:id])
-
site = Site.find(category.festivity_category_type.site_id)
-
category.inactive = true
-
if category.save!
-
render partial: 'admin/sites/partials/filters', :locals => { :category_types => site.festivity_active_category_types}
-
end
-
end
-
-
end
-
class Admin::FestivityCategoryTypesController < Admin::ResourceController
-
-
def index
-
-
end
-
-
def show
-
-
end
-
-
def create
-
site = Site.find(params[:site_id])
-
new_category_type = site.festivity_category_types.new(name: params[:name], page_class: params[:page_class])
-
if new_category_type.save
-
render partial: 'admin/sites/partials/new_category_type', :locals => { :new_category_type => new_category_type, :category_types => site.festivity_active_category_types}
-
else
-
render status: :conflict, text: "Category Type name must be unique."
-
end
-
-
end
-
-
def destroy
-
category_type = FestivityCategoryType.find(params[:id])
-
site = Site.find(category_type.site_id)
-
category_type.inactive = true
-
if category_type.save!
-
render partial: 'admin/sites/partials/category_types', :locals => { :category_types => site.festivity_active_category_types}
-
end
-
end
-
-
end
-
class Admin::FestivityPerformancesController < Admin::ResourceController
-
def create
-
event = FestivityEventPage.find(params[:event_page_id])
-
performance = event.festivity_performances.new
-
if performance.save
-
render partial: 'admin/pages/partials/performance', :locals => {:performance => performance, :locations => FestivityLocationPage.where(site_id: event.site.id) }
-
else
-
render status: :bad_request
-
end
-
-
end
-
-
def destroy
-
performance = FestivityPerformance.find(params[:id])
-
page_id = performance.festivity_event_page.id
-
if performance.destroy
-
render partial: 'admin/pages/partials/performances_table', :locals => { :performances => FestivityEventPage.find(page_id).festivity_performances, :page_id => page_id, locations: FestivityLocationPage.all}
-
end
-
end
-
-
end
-
module Concerns
-
module FestivityCustomPage
-
-
extend ActiveSupport::Concern
-
-
included do
-
include Festivity::Mixins::NotFound
-
no_login_required
-
trusty_layout 'base'
-
end
-
end
-
end
-
module Concerns
-
module FestivitySearchCaching
-
-
extend ActiveSupport::Concern
-
-
included do
-
caches_action :index, cache_path: proc { |c| c.params.except(:_).merge(format: request.xhr?, base_domain: "#{request.subdomain}.#{request.domain}")}
-
caches_action :show
-
end
-
end
-
end
-
module Concerns
-
module FestivitySqlBuilder
-
-
extend ActiveSupport::Concern
-
-
included do
-
-
def self.advance_by(filter_type)
-
advance_by_hash = {minutes: 59}
-
advance_by_hash[:hours] = 23 if filter_type == "date"
-
advance_by_hash
-
end
-
-
def self.parse_categories(category_ids)
-
grouped_ids = FestivityCategory.find(category_ids).group_by {|category| category.festivity_category_type}
-
category_clauses = grouped_ids.map do |categories|
-
"page_id IN (SELECT page_id FROM festivity_page_categories WHERE festivity_category_id IN (#{categories[1].map {|category| category.id}.join(",")}))"
-
end
-
"(#{category_clauses.join(" AND ")})"
-
-
end
-
-
end
-
end
-
end
-
class ErrorsController < ApplicationController
-
include Concerns::FestivityCustomPage
-
-
def internal_server_error
-
render(:status => 500)
-
end
-
end
-
class FestivityEventsController < ApplicationController
-
include Concerns::FestivityCustomPage
-
include Concerns::FestivitySearchCaching
-
before_action { expires_in 1.hour, :public => true }
-
-
def index
-
order_by = params[:sort] ? params[:sort] : "start_date"
-
@title = "#{current_site.festivity_festival_name}: Events"
-
@filter_type = current_site.festivity_filter_type
-
@events = Rails.cache.fetch("#{cache_key}", expires_in: 2.hours) do
-
FestivityEventList.search(
-
{dates: search_dates.join(","),
-
categories: params[:categories],
-
filter_type: current_site.festivity_filter_type},
-
order_by).events
-
end
-
-
-
@selected_dates = params[:dates] ? FestivityDatetimeFilterPresenter.parse(params[:dates].split(","), current_site.festivity_filter_type) : []
-
@selected_categories = params[:categories] ? params[:categories].split(",") : []
-
@selected_sort = order_by
-
# If the request is AJAX, only return the event list itself, not the full page
-
if request.xhr?
-
render partial: "event_list"
-
else
-
render 'index'
-
end
-
-
end
-
-
def show
-
@event = FestivityEventPage.find_by_slug_and_status_id(params[:id], Status[:published].id)
-
if @event
-
@page = @event
-
@related_events = FestivityEventList.find_related_events(
-
{dates: search_dates.join(","), event_id: @event.id,
-
categories: @event.festivity_categories.map{|cat| cat.id}}).events
-
@title = "#{current_site.festivity_festival_name}: #{@event.title}"
-
else
-
file_not_found_for_site
-
end
-
-
end
-
-
private
-
-
def cache_key
-
"events-#{params[:categories.to_s]}-#{params[:dates].to_s}-#{params[:sort].to_s}-#{request.xhr?}-#{request.subdomain}.#{request.domain}"
-
end
-
-
def search_dates
-
if params[:dates]
-
params[:dates].split(",")
-
else
-
FestivityEventList.collect_festival_dates(current_site)
-
end
-
-
end
-
-
-
end
-
class FestivityLocationAreasController < ApplicationController
-
include Concerns::FestivityCustomPage
-
before_action { expires_in 1.hour, :public => true }
-
-
def show
-
@area = FestivityLocationAreaPage.find_by_slug_for_site(params[:id]).first
-
-
if @area
-
@title = "#{current_site.festivity_festival_name}: #{@area.title}"
-
else
-
file_not_found_for_site
-
end
-
-
end
-
-
end
-
class FestivityLocationsController < ApplicationController
-
include Concerns::FestivityCustomPage
-
before_action { expires_in 1.hour, :public => true }
-
-
def show
-
@location = FestivityLocationPage.find_by_slug_for_site(params[:id]).first
-
if @location
-
@location_events = @title = Rails.cache.fetch("location-#{@location.slug}", expires_in: 2.hours) do
-
FestivityEventList.find_by_location(@location.id, current_site)
-
end
-
@title = "#{current_site.festivity_festival_name}: #{@location.title}"
-
else
-
file_not_found_for_site
-
end
-
-
end
-
-
end
-
class FestivityMarketsController < ApplicationController
-
include Concerns::FestivityCustomPage
-
include Concerns::FestivitySearchCaching
-
before_action { expires_in 1.hour, :public => true }
-
-
def index
-
-
order_by = params[:sort] ? params[:sort] : "start_date"
-
@title = "#{current_site.festivity_festival_name}: Artist's Market"
-
@filter_type = current_site.festivity_filter_type
-
@markets = Rails.cache.fetch("#{cache_key}", expires_in: 2.hours) do
-
FestivityMarketList.search(
-
{dates: search_dates.join(","),
-
categories: params[:categories],
-
filter_type: current_site.festivity_filter_type}, order_by
-
).markets
-
end
-
-
-
@selected_dates = params[:dates] ? FestivityDatetimeFilterPresenter.parse(params[:dates].split(","), current_site.festivity_filter_type) : []
-
@selected_categories = params[:categories] ? params[:categories].split(",") : []
-
@selected_sort = order_by
-
# If the request is AJAX, only return the market list itself, not the full page
-
if request.xhr?
-
render partial: "market_list"
-
else
-
render 'index'
-
end
-
-
end
-
-
def show
-
@market = FestivityMarketPage.find_by_slug_and_status_id(params[:id], Status[:published].id)
-
if @market
-
@page = @market
-
@title = "#{current_site.festivity_festival_name}: #{@market.title}"
-
else
-
file_not_found_for_site
-
end
-
-
end
-
-
private
-
-
def cache_key
-
"markets-#{params[:categories.to_s]}-#{params[:dates].to_s}-#{params[:sort].to_s}-#{request.xhr?}-#{request.subdomain}.#{request.domain}"
-
end
-
-
def search_dates
-
if params[:dates]
-
params[:dates].split(",")
-
else
-
collect_festival_dates
-
end
-
-
end
-
-
def collect_festival_dates
-
festival_dates = current_site.festival_datetimes
-
if current_site.date_during_festival?(Time.now)
-
festival_dates = festival_dates.select{ |date| date.datetime == Time.now }
-
end
-
-
festival_dates.map{ |date| date.to_s }
-
-
end
-
-
end
-
class SearchController < ApplicationController
-
include Concerns::FestivityCustomPage
-
before_action { expires_in 1.hour, :public => true }
-
-
def show
-
query = params[:q].to_s
-
@keyword = query
-
@page_number = page_number
-
@result = GoogleCustomSearch::Search.new.with_page_index(@page_number).for url_encode("#{@keyword} site:#{current_site.base_domain}")
-
end
-
-
private
-
def page_number
-
page_number = params[:page_number] || 1
-
page_number.to_i
-
end
-
end
-
module Admin::FestivityPerformancesHelper
-
include Admin::PagesHelper
-
end
-
1
module Admin::SnippetsHelper
-
-
end
-
module FestivityEventsHelper
-
include RadSocialHelper
-
-
def date_time_popover(performances)
-
"<div><ul class='list-unstyled'>#{date_time_list_items(performances)}</ul></div>"
-
end
-
-
def date_time_list_items(performances)
-
performances.map {|perf| "<li>#{perf.start_date.strftime('%A, %B %d')}, #{perf.start_date.strftime('%I:%M %p').downcase} - #{perf.end_date.strftime('%I:%M %p').downcase}</li>" }.join("")
-
end
-
-
def social_share_message(production)
-
"Check out #{production.title} for #{fest_hashtag} @ #{production.locations.first.title}!"
-
end
-
-
def social_share_email_subject(production)
-
"Check out #{production.title}"
-
end
-
-
def social_share_email_message(production)
-
"I thought you might be interested in seeing #{production.title}."
-
end
-
-
def shared_production_url
-
"#{event_url}?cid=CDSocial"
-
end
-
-
def fest_hashtag
-
current_site.social_media_tag
-
end
-
-
end
-
module FestivityLocationsHelper
-
include FestivityEventsHelper
-
-
end
-
1
module Concerns
-
1
module FestivityArtistMethods
-
-
1
include ActiveSupport::Concern
-
-
1
def has_social?
-
(has_twitter? or has_facebook? or has_homepage? or has_instagram?)
-
end
-
-
1
def has_twitter?
-
!self.artist_twitter.empty?
-
end
-
-
1
def has_facebook?
-
!self.artist_facebook.empty?
-
end
-
-
1
def has_instagram?
-
!self.artist_instagram.empty?
-
end
-
-
1
def has_homepage?
-
!self.artist_homepage.empty?
-
end
-
-
-
end
-
end
-
1
class FestivityBasePage < Page
-
-
1
def body
-
self.part("body").content.html_safe
-
end
-
-
1
def sponsor_logo
-
self.part("sponsor_logo").content.html_safe
-
end
-
-
1
def sponsor_logo?
-
!self.part("sponsor_logo").content.empty?
-
end
-
-
1
def video
-
self.part("video_embed").content.html_safe
-
end
-
-
1
def video?
-
!self.part("video_embed").content.empty?
-
end
-
-
end
-
class FestivityCategory < ActiveRecord::Base
-
acts_as_list :scope => :parent_id
-
belongs_to :festivity_category_type
-
has_many :pages, through: :festivity_page_categories
-
#self.reflections[:children].options[:position] = "position ASC"
-
-
attr_accessible :name, :festivity_category_type_id, :parent_id, :position, :inactive
-
-
def parent
-
FestivityCategory.find(self.parent_id)
-
end
-
-
def children
-
FestivityCategory.where(parent_id: self.id, inactive: false)
-
end
-
-
end
-
class FestivityCategoryType < ActiveRecord::Base
-
acts_as_list scope: :site_id
-
has_many :festivity_categories
-
belongs_to :site
-
validates_uniqueness_of :name, scope: :site_id
-
-
attr_accessible :name, :page_class
-
-
-
def parent_categories
-
self.festivity_categories.where(inactive: false, parent_id: nil)
-
end
-
-
end
-
class FestivityEventList
-
-
include Concerns::FestivitySqlBuilder
-
-
attr_reader :events
-
-
def initialize(event_performances)
-
@events = event_performances.group_by {|perf| perf.event_id }.
-
map { |perfs| FestivityEventList::FestivityEvent.new(perfs[0], perfs[1]) }
-
-
end
-
-
def self.search(criteria, order_by)
-
begin
-
where_clause = parse_criteria(criteria)
-
rescue ActiveRecord::RecordNotFound
-
return FestivityEventList.new([])
-
end
-
-
# where in event ids
-
FestivityEventList.new(
-
FestivityEventList::FestivityEventPerformance.
-
includes(:assets).
-
joins(:festivity_categories).
-
where(where_clause).
-
group("performance_id").
-
order("featured_item DESC, #{order_by} ASC").
-
preload(:festivity_categories)
-
)
-
end
-
-
def self.hourly
-
current_site = Page.current_site
-
festival_date_times = FestivityEventList.collect_festival_dates(current_site)
-
festival_dates = festival_date_times.map! {|date| date.to_date}
-
-
if festival_dates.include?(DateTime.now.to_date)
-
FestivityPerformance.where(start_date: DateTime.now...DateTime.now + 1.day).includes(:festivity_event_page).where(pages: {status_id: 100, site_id: Page.current_site.id, layout_id: nil}).compact.sort_by{|e| e[:date]}.first(3)
-
elsif festival_dates.first > DateTime.now.to_date
-
FestivityPerformance.includes(:festivity_event_page).where(pages: {status_id: 100, site_id: current_site.id, layout_id: nil}).compact.sort_by{|e| e[:date]}.first(3)
-
else
-
FestivityPerformance.includes(:festivity_event_page).where(pages: {status_id: 100, site_id: current_site.id, layout_id: nil}).compact.sort_by{|e| e[:date]}.last(3)
-
end
-
end
-
-
def self.find_by_location(location_id, site)
-
begin
-
where_clause = parse_criteria(dates: collect_festival_dates(site).join(","), filter_type: site.festivity_filter_type)
-
rescue ActiveRecord::RecordNotFound
-
return FestivityEventList.new([])
-
end
-
-
FestivityEventList.new(
-
FestivityEventList::FestivityEventPerformance.
-
includes(:assets).
-
joins(:festivity_categories).
-
where(where_clause).
-
where(location_id: location_id).
-
group("performance_id").
-
order("featured_item DESC, start_date ASC").
-
preload(:festivity_categories)
-
)
-
end
-
-
def self.find_related_events(criteria)
-
where_clause = parse_criteria(criteria)
-
FestivityEventList.new(
-
FestivityEventList::FestivityEventPerformance.
-
includes(:assets).
-
joins(:festivity_categories).
-
where(where_clause).
-
where("event_id != ?", criteria[:event_id]).
-
group("performance_id").
-
order("featured_item DESC, start_date ASC").
-
preload(:festivity_categories)
-
)
-
end
-
-
def self.collect_festival_dates(site)
-
festival_dates = site.festival_datetimes
-
if site.date_during_festival?(Time.now)
-
festival_dates = festival_dates.select{ |date| date.datetime == Time.now }
-
end
-
-
festival_dates.map{ |date| date.to_s }
-
-
end
-
-
private
-
-
# Return a list of unique event ids that match the provided dates
-
def self.event_ids_for_datetimes(datetimes, filter_type)
-
FestivityEventList::FestivityEventPerformance.where(datetime_criteria(datetimes, filter_type)).map {|e| e.event_id}.uniq
-
end
-
-
# Create a condition for start and end date between midnight and 11:59pm
-
# for each date passed in and return the SQL condition
-
def self.datetime_criteria(datetimes_string, filter_type)
-
-
date_queries = datetimes_string.split(',').map do |date_string|
-
start_date = Chronic.parse(URI.decode(date_string)).utc
-
end_date = start_date.advance(advance_by(filter_type))
-
<<-SQL
-
(
-
(start_date >= '#{start_date}' AND start_date <= '#{end_date}')
-
OR
-
(end_date >= '#{start_date}' AND end_date <= '#{end_date}')
-
)
-
SQL
-
end
-
date_queries.join(" OR ")
-
end
-
-
-
# The order of querying, depending on what is passed:
-
# - If dates are passed, we search both start and end date between midnight and 11:59pm of that date.
-
# That query returns any matching event ids.
-
# - The event ids returned, if any, are added to the where clause for the next query
-
# - Any category ids passed are added to the where clause as well.
-
def self.parse_criteria(criteria)
-
if criteria[:dates]
-
# related events fails if filter_type is nil - this is a fallback for nil filter_type
-
site_filter = Site.find_by_id(Page.current_site.id).festivity_filter_type
-
filter = criteria[:filter_type] ||= site_filter
-
event_ids = event_ids_for_datetimes(criteria[:dates], filter)
-
raise ActiveRecord::RecordNotFound unless event_ids.any?
-
end
-
-
where_clause = "site_id = #{ Page.current_site.id}"
-
where_clause += " AND event_id IN (#{event_ids.join(",")})" if event_ids.present?
-
where_clause += " AND #{parse_categories(criteria[:categories].split(","))}" if criteria[:categories]
-
where_clause
-
end
-
-
-
end
-
-
class FestivityEventList::FestivityEvent
-
include Festivity::Admin::AssetsHelper
-
-
attr_reader :id, :performances, :locations, :categories, :title, :short_description,
-
:assets, :header, :sub_header, :featured_item, :buy_url
-
-
def initialize(event_id, performances)
-
@id = event_id
-
@performances = performances
-
@title = performances.first.event_title
-
@short_description = performances.first.short_description
-
@header = performances.first.header
-
@sub_header = performances.first.sub_header
-
@featured_item = performances.first.featured_item
-
@buy_url = performances.first.buy_url
-
-
@locations = self.performances.
-
map{ |performance| FestivityEventList::FestivityLocation.new ({
-
id: performance.location_id,
-
slug: performance.location_slug,
-
title: performance.location_title,
-
directions_url: performance.festivity_directions_url,
-
area_id: performance.area_id,
-
area_slug: performance.area_slug,
-
area_title: performance.area_title}) }.
-
uniq{ |location| location.id }
-
-
@categories = performances.first.festivity_categories
-
-
@assets = performances.first.assets
-
-
end
-
-
def image
-
image = assets.select { |asset| asset.title == "featured_image" }.first if assets.size > 0
-
image.thumbnail(:normal) unless image.nil?
-
end
-
-
-
end
-
class FestivityEventList::FestivityEventPerformance < ActiveRecord::Base
-
self.table_name = 'festivity_event_performances'
-
after_initialize :readonly!
-
-
has_many :festivity_page_categories, foreign_key: :page_id, primary_key: :event_id
-
has_many :festivity_categories, through: :festivity_page_categories
-
has_many :page_attachments, primary_key: :event_id, foreign_key: :page_id
-
has_many :assets, through: :page_attachments
-
-
end
-
class FestivityEventList::FestivityLocation
-
-
attr_reader :id, :title, :slug, :area_id, :area_title, :area_slug, :directions_url
-
-
def initialize(location_hash)
-
@id = location_hash[:id]
-
@title = location_hash[:title]
-
@slug = location_hash[:slug]
-
@directions_url = location_hash[:directions_url]
-
@area_id = location_hash[:area_id]
-
@area_title = location_hash[:area_title]
-
@area_slug = location_hash[:area_slug]
-
end
-
-
end
-
1
class FestivityEventPage < FestivityBasePage
-
1
has_many :festivity_performances, foreign_key: :event_page_id
-
1
has_many :festivity_page_categories, foreign_key: :page_id
-
1
has_many :festivity_categories, through: :festivity_page_categories
-
-
1
include Concerns::FestivityArtistMethods
-
-
1
def festivity_performances=(performances)
-
performances.each do |performance|
-
performance_id = performance.delete(:performance_id)
-
FestivityPerformance.find(performance_id).update_attributes(performance)
-
end
-
end
-
-
1
def performances
-
self.festivity_performances.select {|perf| perf.festivity_location_page && perf.start_date && perf.end_date }
-
end
-
-
1
def single_location?
-
@single_location ||= self.locations.count == 1
-
end
-
-
1
def locations
-
@locations ||= event_locations
-
end
-
-
1
def can_buy?
-
!self.buy_url.empty?
-
end
-
-
1
def event_locations
-
# Return array of unique locations
-
self.performances.
-
map{ |performance| performance.festivity_location_page }.
-
uniq{ |location| location.id }
-
end
-
-
-
end
-
1
class FestivityLocationAreaPage < Page
-
1
def body
-
self.part("body").content.html_safe
-
end
-
end
-
1
class FestivityLocationPage < Page
-
1
has_many :festivity_performances, foreign_key: :location_page_id
-
-
1
def body
-
self.part("body").content.html_safe
-
end
-
end
-
class FestivityMarketList
-
-
include Concerns::FestivitySqlBuilder
-
-
attr_reader :markets
-
-
-
def initialize(market_details)
-
@markets = market_details
-
end
-
-
def self.search(criteria, order_by)
-
begin
-
where_clause = parse_criteria(criteria)
-
rescue ActiveRecord::RecordNotFound
-
return FestivityMarketList.new([])
-
end
-
-
# where in market ids
-
FestivityMarketList.new(
-
FestivityMarketList::FestivityMarketDetail.
-
includes(:assets).
-
joins(:festivity_categories).
-
where(where_clause).
-
order("#{order_by} ASC").
-
preload(:festivity_categories)
-
)
-
end
-
-
-
private
-
-
-
# Return a list of unique market ids that match the provided dates
-
def self.market_ids_for_datetimes(datetimes, filter_type)
-
FestivityMarketList::FestivityMarketDetail.where(datetime_criteria(datetimes, filter_type)).map {|e| e.market_id}.uniq
-
end
-
-
# Create a condition for start and end date between midnight and 11:59pm
-
# for each date passed in and return the SQL condition
-
def self.datetime_criteria(datetimes_string, filter_type)
-
-
date_queries = datetimes_string.split(',').map do |date_string|
-
start_date = Chronic.parse(URI.decode(date_string)).utc
-
end_date = start_date.advance(advance_by(filter_type))
-
<<-SQL
-
(
-
(start_date <= '#{start_date}' AND end_date >= '#{end_date}')
-
OR
-
(end_date >= '#{start_date}' AND start_date <= '#{end_date}')
-
)
-
SQL
-
end
-
date_queries.join(" OR ")
-
end
-
-
-
# The order of querying, depending on what is passed:
-
# - If dates are passed, we search both start and end date between midnight and 11:59pm of that date.
-
# That query returns any matching market ids.
-
# - The market ids returned, if any, are added to the where clause for the next query
-
# - Any category ids passed are added to the where clause as well.
-
-
def self.parse_criteria(criteria)
-
if criteria[:dates]
-
market_ids = market_ids_for_datetimes(criteria[:dates], criteria[:filter_type])
-
raise ActiveRecord::RecordNotFound unless market_ids.any?
-
end
-
-
where_clause = "site_id = #{ Page.current_site.id}"
-
where_clause += " AND market_id IN (#{market_ids.join(",")})" if market_ids.present?
-
where_clause += " AND #{parse_categories(criteria[:categories].split(","))}" if criteria[:categories]
-
where_clause
-
end
-
-
end
-
class FestivityMarketList::FestivityMarketDetail < ActiveRecord::Base
-
self.table_name = 'festivity_market_details'
-
after_initialize :readonly!
-
-
has_many :festivity_page_categories, foreign_key: :page_id, primary_key: :market_id
-
has_many :festivity_categories, through: :festivity_page_categories
-
has_many :page_attachments, primary_key: :market_id, foreign_key: :page_id
-
has_many :assets, through: :page_attachments
-
-
-
def id
-
market_id
-
end
-
-
def categories
-
festivity_categories
-
end
-
-
def image
-
image = assets.select { |asset| asset.title == "featured_image" }.first if assets.size > 0
-
image.thumbnail(:normal) unless image.nil?
-
end
-
-
end
-
1
class FestivityMarketPage < FestivityBasePage
-
-
1
include Concerns::FestivityArtistMethods
-
1
has_many :festivity_categories, through: :festivity_page_categories
-
-
1
def area
-
FestivityLocationAreaPage.find(area_id)
-
end
-
-
1
def self.booth_number(market_id)
-
self.find_by_id(market_id).booth_number
-
end
-
-
end
-
class FestivityPageCategory < ActiveRecord::Base
-
belongs_to :festivity_category
-
belongs_to :page
-
end
-
class FestivityPerformance < ActiveRecord::Base
-
validates_presence_of :event_page_id
-
belongs_to :festivity_event_page, foreign_key: :event_page_id
-
belongs_to :festivity_location_page, foreign_key: :location_page_id
-
default_scope {order :start_date}
-
-
attr_accessible :start_date, :end_date, :festivity_location_page, :notes
-
-
def start_date=(date)
-
super(parse_date(date))
-
end
-
-
def end_date=(date)
-
super(parse_date(date))
-
end
-
-
def festivity_location_page=(location)
-
super(FestivityLocationPage.find(location[:id])) unless location[:id].blank?
-
end
-
-
def location
-
FestivityLocationPage.find_by_id(self.location_page_id).title
-
end
-
-
def area
-
location = FestivityLocationPage.find_by_id(self.location_page_id).parent_id
-
FestivityLocationAreaPage.find_by_id(location).title
-
end
-
-
-
private
-
-
def parse_date(date)
-
Chronic.parse(date)
-
rescue
-
nil
-
end
-
-
end
-
1
class VanityUrlPage < Page
-
-
1
def clean_target_url
-
(self.target_url.match('http://') || self.target_url.match('https://')) ? self.target_url : VanityUrlPage.clean_path(self.target_url)
-
end
-
-
1
class << self
-
-
1
def find_vanity_url_by_path(path, live = true)
-
vanity_url_page = Page.current_site.homepage.children.find_by_slug('vanity-urls')
-
vanity_pages = vanity_url_page.children.where("vanity_url like '%#{path}%'")
-
vanity_pages.each do |vanity_page|
-
return vanity_page if clean_comparison_path(path).downcase == clean_comparison_path(vanity_page.vanity_url).downcase
-
end
-
nil
-
end
-
-
1
def clean_comparison_path(path)
-
"#{clean_path(path)}/"
-
end
-
-
1
def clean_path(path)
-
"/#{path.to_s.strip}".gsub(%r{//+}, '/')
-
end
-
-
end
-
-
end
-
class FestivityDatePresenter < FestivityDatetimePresenter
-
-
def display
-
display_as_date
-
end
-
-
end
-
class FestivityDatetimeFilterPresenter
-
-
def self.new(datetimes, datetime_type)
-
datetimes.map { |datetime| datetime_type_class(datetime_type).new(datetime) }
-
-
end
-
-
def self.parse(datetimes, datetime_type)
-
self.new(datetimes.map{|date| Chronic.parse(date)}, datetime_type)
-
end
-
-
private
-
-
def self.datetime_type_class(datetime_type)
-
datetime_type == "date" ? FestivityDatePresenter : FestivityTimePresenter
-
end
-
-
end
-
class FestivityDatetimePresenter
-
attr_reader :datetime
-
-
def initialize(datetime)
-
@datetime = datetime
-
end
-
-
def ==(other_object)
-
@datetime == other_object.datetime
-
end
-
-
def display_as_date
-
@datetime.strftime("%a, %B %-d")
-
end
-
-
def to_s
-
@datetime.to_s
-
end
-
-
def to_date
-
@datetime.to_date
-
end
-
-
def display_as_time_range
-
"#{display_start_time} - #{display_end_time}"
-
end
-
-
def display_start_time
-
@datetime.strftime(display_time_format)
-
end
-
-
def display_end_time
-
(@datetime + 1.hour).strftime(display_time_format)
-
end
-
-
def display_time_format
-
"%l:%M %P"
-
end
-
-
end
-
class FestivityTimePresenter < FestivityDatetimePresenter
-
-
def display
-
display_as_time_range
-
end
-
-
end
-
module Social
-
class FeedPresenter
-
-
def initializer
-
-
end
-
-
end
-
end
-
Social::InstagramPostPresenter = ImmutableStruct.new(
-
:user_full_name,
-
:user_id,
-
:user_profile_picture_url,
-
:user_username,
-
:id,
-
:text,
-
:filter,
-
:id,
-
:low_res_image_url,
-
:low_res_image_height,
-
:low_res_image_width,
-
:standard_res_image_url,
-
:standard_res_image_height,
-
:standard_res_image_width,
-
:thumbnail_image_url,
-
:thumbnail_res_image_height,
-
:thumbnail_res_image_width,
-
:url,
-
:created_time
-
) do
-
-
def self.from_instagram_post(post)
-
self.new(user_profile_picture_url: post.user.profile_picture,
-
user_full_name: post.user.full_name,
-
user_id: post.user.id,
-
user_username: post.user.username,
-
id: post.id,
-
created_time: Time.at(post.created_time.to_i),
-
text: post.caption.text,
-
filter: post.filter,
-
low_res_image_url: post.images.low_resolution.url,
-
low_res_image_height: post.images.low_resolution.height,
-
low_res_image_width: post.images.low_resolution.width,
-
standard_res_image_url: post.images.standard_resolution.url,
-
standard_res_image_height: post.images.standard_resolution.height,
-
standard_res_image_width: post.images.standard_resolution.width,
-
thumbnail_image_url: post.images.thumbnail.url,
-
thumbnail_image_height: post.images.thumbnail.height,
-
thumbnail_image_width: post.images.thumbnail.width,
-
url: post.link)
-
-
end
-
end
-
Social::TwitterPostPresenter = ImmutableStruct.new(
-
:user_full_name,
-
:user_id,
-
:user_profile_picture_url,
-
:user_username,
-
:id,
-
:text,
-
:filter,
-
:id,
-
:low_res_image_url,
-
:low_res_image_height,
-
:low_res_image_width,
-
:standard_res_image_url,
-
:standard_res_image_height,
-
:standard_res_image_width,
-
:thumbnail_image_url,
-
:thumbnail_res_image_height,
-
:thumbnail_res_image_width,
-
:url,
-
:created_time
-
) do
-
-
def self.from_twitter_post(post)
-
self.new(user_full_name: post.user.name,
-
user_id: post.user.id,
-
user_username: post.user.screen_name,
-
id: post.id,
-
created_time: post.created_at,
-
text: post.text,
-
url: post.url)
-
end
-
end
-
class InstagramFeedService
-
-
def initialize
-
@client = Instagram.client
-
end
-
-
def get_feed_for_tag(tag)
-
@client.tag_recent_media(tag).map do |post|
-
Social::InstagramPostPresenter.from_instagram_post(post)
-
end
-
end
-
-
end
-
class SocialFeedService
-
-
def initialize
-
-
end
-
-
def get_feed(options)
-
-
end
-
-
-
private
-
-
def query_feeds(options)
-
-
end
-
-
end
-
class TwitterFeedService
-
-
def initialize
-
# @client = Twitter::REST::Client.new(config)
-
@client = $twitter_client
-
end
-
-
#note: needed to remove trafficjamnet because of the bogus TRAF tweets they do
-
-
def get_feed_for_tag(tag)
-
@client.search("##{tag} -rt -from:trafficjamnet", result_type: "recent", lang: "en").take(50).each do |tweet|
-
Social::TwitterPostPresenter.from_twitter_post(tweet)
-
end
-
end
-
-
end
-
# Uncomment this if you reference any of your controllers in activate
-
# require_dependency "application_controller"
-
1
require "trusty-festivity-extension"
-
1
class FestivityExtension < TrustyCms::Extension
-
1
version TrustyFestivityExtension::VERSION
-
1
description TrustyFestivityExtension::DESCRIPTION
-
1
url TrustyFestivityExtension::URL
-
-
1
def activate
-
require 'fog'
-
require 'actionpack/action_caching'
-
admin.page.edit.add(:form, "festivity_includes", :before => 'edit_page_parts')
-
admin.page.edit.add(:form, "festivity_featured_image_fields", :after => 'edit_page_parts')
-
admin.page.edit.add(:form, "festivity_base_fields", :after => 'edit_page_parts')
-
admin.page.edit.add(:form, "festivity_location_fields", :after => 'edit_page_parts')
-
admin.site.edit.add(:form, "festivity_site_fields", :after => 'edit_homepage')
-
admin.page.edit.add(:form, "festivity_vanity_url_fields", :before => 'form_bottom')
-
-
Admin::AssetsController.send :include, Festivity::Extensions::PaperclippedExtensions
-
Site.send :include, Festivity::Extensions::SiteExtensions
-
#Page.send :include, Festivity::Extensions::PageExtensions
-
Admin::PagesHelper.send :include, Festivity::Extensions::PagesHelperExtensions
-
SitesHelper.send :include, Festivity::Extensions::PagesHelperExtensions
-
Page.send :include, Tags::NavigationTags
-
Page.send :include, Tags::HeaderTags
-
Page.send :include, Tags::FilterAndMenuTags
-
Page.send :include, Tags::SocialFeedTags
-
end
-
-
end
-
module Festivity
-
module Admin
-
module AssetsHelper
-
-
def page_image_url(title)
-
image = assets.find_by_title(title) if assets.size > 0
-
image.thumbnail(:normal) unless image.nil?
-
end
-
-
def page_image_url_from_all_assets title
-
image = Asset.find_by_title(title)
-
image.thumbnail(:normal) unless image.blank?
-
end
-
-
end
-
end
-
end
-
1
module Festivity
-
1
class Engine < Rails::Engine
-
1
paths["app/helpers"] = []
-
-
1
initializer "trusty_cms.assets.precompile" do |app|
-
1
app.config.assets.precompile += %w(
-
main.css
-
skins/crawl/skin.css
-
skins/first-night/skin.css
-
skins/pghkids/skin.css
-
skins/traf/skin.css
-
admin/festivity_admin.css
-
admin/festivity_admin.js
-
festivity_app.js
-
grunticon/production/grunticon.loader.js
-
grunticon/production/*.css)
-
end
-
end
-
-
end
-
module Festivity
-
module Extensions
-
module PageExtensions
-
-
def self.included(base)
-
base.class_eval {
-
-
before_save :set_page_defaults
-
after_create :create_page_defaults
-
-
has_many :festivity_category_types
-
has_many :festivity_page_categories
-
has_many :festivity_categories, through: :festivity_page_categories
-
-
include ActsAsTree::InstanceMethods
-
include Festivity::Extensions::PageExtensions::PageMethods
-
include Festivity::Admin::AssetsHelper
-
-
alias_method_chain :find_by_path, :vanity_urls
-
}
-
-
end
-
-
module PageMethods
-
-
def create_page_defaults
-
self.save if festivity_base_page?
-
end
-
-
def set_page_defaults
-
if festivity_base_page? && self.id
-
self.slug = self.id unless self.slug == self.id
-
parts.create(:name => 'video_embed', :content => "") unless parts.any? { |part| part.name == 'video_embed' }
-
parts.create(:name => 'sponsor_logo', :content => "") unless parts.any? { |part| part.name == 'sponsor_logo' }
-
end
-
end
-
-
def image
-
page_image_url('featured_image')
-
end
-
-
def market_start_date=(value)
-
super(Chronic.parse(value))
-
end
-
-
def market_end_date=(value)
-
super(Chronic.parse(value))
-
end
-
-
def organization
-
page_organization = nil
-
page_parent = self.parent
-
while page_organization == nil
-
page_organization = page_parent.site
-
page_parent = page_parent.parent
-
end
-
page_organization
-
end
-
-
def find_by_path_with_vanity_urls(path, live = true, clean = true)
-
raise MissingRootPageError unless root
-
page = self.find_by_path_without_vanity_urls(path, live, clean)
-
if page.is_a?(FileNotFoundPage)
-
vanity_url = VanityUrlPage.find_vanity_url_by_path(path, live)
-
end
-
vanity_url ? vanity_url : page
-
end
-
-
private
-
-
def festivity_base_page?
-
(self.class_name == "FestivityEventPage") | (self.class_name == "FestivityMarketPage")
-
end
-
-
end
-
-
end
-
end
-
end
-
-
module Festivity::Extensions::PagesHelperExtensions
-
-
def self.included(base)
-
base.class_eval do
-
def format_date(date)
-
date.strftime('%m/%d/%Y %I:%M %p') if date
-
end
-
end
-
end
-
-
end
-
module Festivity
-
module Extensions
-
module PaperclippedExtensions
-
-
def async_create
-
@asset = Asset.new(params[:asset])
-
if @asset.save
-
if params[:page]
-
@page = Page.find(params[:page])
-
existing_asset = @page.assets.find_by_title(@asset.title)
-
@page.assets.delete(existing_asset) if not existing_asset.nil?
-
@asset.pages << @page
-
end
-
render :text => @asset.thumbnail(:thumbnail)
-
else
-
head :internal_server_error
-
end
-
end
-
-
end
-
end
-
end
-
module Festivity
-
module Extensions
-
module SiteControllerExtensions
-
-
def self.included(base)
-
base.class_eval do
-
alias_method_chain :process_page, :redirection
-
end
-
end
-
-
-
def process_page_with_redirection(page)
-
if page.is_a?(VanityUrlPage)
-
false if redirect_to page.clean_target_url
-
-
elsif !page.redirect_url.nil? && !page.redirect_url.empty?
-
false if redirect_to page.redirect_url
-
else
-
process_page_without_redirection(page)
-
end
-
end
-
-
-
end
-
end
-
end
-
-
module Festivity
-
module Extensions
-
module SiteExtensions
-
-
def self.included(base)
-
base.class_eval {
-
has_many :festivity_category_types
-
include Festivity::Extensions::SiteExtensions::SiteMethods
-
}
-
end
-
-
module SiteMethods
-
-
def festivity_start_date=(value)
-
super(Chronic.parse(value))
-
end
-
-
def festivity_end_date=(value)
-
super(Chronic.parse(value))
-
end
-
-
def festivity_active_category_types()
-
self.festivity_category_types.where(["inactive = false"])
-
end
-
-
def festivity_active_category_types_for(page_class)
-
self.festivity_category_types.where(["inactive = false AND page_class = '#{page_class}'"])
-
end
-
-
def date_during_festival?(date)
-
self.festival_datetimes.any? {|festival_date| festival_date.datetime == date}
-
end
-
-
def festival_datetimes
-
@festival_datetimes ||= calculate_festival_datetimes
-
end
-
-
def calculate_festival_datetimes
-
dates = [self.festivity_start_date]
-
advance_by = date_filter? ? {days: 1} : {hours: 1}
-
until dates.last.advance(advance_by) >= self.festivity_end_date do
-
dates << dates.last.advance(advance_by)
-
end
-
FestivityDatetimeFilterPresenter.new(dates, self.festivity_filter_type)
-
rescue
-
[]
-
end
-
-
def date_filter?
-
self.festivity_filter_type == "date"
-
end
-
-
end
-
-
end
-
end
-
end
-
module Festivity::Mixins::NotFound
-
-
def file_not_found_for_site
-
not_found_page = FileNotFoundPage.where(site_id: current_site.id).first
-
not_found_page.process(request, response)
-
@performed_render ||= true
-
render 'site/show_page', layout: false
-
end
-
-
end
-
module Tags::FilterAndMenuTags
-
include TrustyCms::Taggable
-
-
desc "Meta Tags"
-
tag "festivity_mobile_menus" do |tag|
-
if request.env["action_controller.instance"].class == FestivityEventsController && request.env["action_controller.instance"].action_name == "index"
-
selected_dates = request.env["action_controller.instance"].params["dates"] ? FestivityDatetimeFilterPresenter.parse(request.env["action_controller.instance"].params["dates"].split(","), Page.current_site.festivity_filter_type) : []
-
selected_categories = request.env["action_controller.instance"].params["categories"] ? request.env["action_controller.instance"].params["categories"].split(",") : []
-
request.env["action_controller.instance"].render_to_string :partial => "festivity_events/filters",
-
:locals => {:selected_dates => selected_dates,
-
:selected_categories => selected_categories}
-
end
-
end
-
-
desc "Render homepage performances on an hourly basis"
-
tag "homepage_performances" do |tag|
-
request.env["action_controller.instance"].render_to_string :partial => "festivity_events/hourly"
-
end
-
end
-
module Tags::HeaderTags
-
include TrustyCms::Taggable
-
-
desc "Meta Tags"
-
tag "festivity_meta" do |tag|
-
page = Page.find_by_slug_for_site(tag.locals.page.slug).first
-
page = Page.current_site.homepage unless page
-
description = get_content(page, :description)
-
keywords = get_content(page, :keywords)
-
domain = "#{request.protocol}#{request.host}"
-
request.env["action_controller.instance"].render_to_string :partial => "header/meta_tags",
-
:locals => {:domain => domain,
-
:description => description,
-
:keywords => keywords,
-
:page => page,
-
:url => request.url}
-
-
end
-
-
desc "body class"
-
tag "festivity_body_class" do |tag|
-
page = Page.find_by_slug_for_site(tag.locals.page.slug).first
-
body_class = page && page == Page.current_site.homepage ? "home" : "internal"
-
action_controller = request.env["action_controller.instance"].class
-
if (action_controller == FestivityEventsController || action_controller == FestivityMarketsController) && request.env["action_controller.instance"].action_name == "index"
-
body_class += " events-list"
-
elsif (action_controller == FestivityEventsController || action_controller == FestivityMarketsController) && request.env["action_controller.instance"].action_name == "show"
-
body_class += " event-detail"
-
end
-
body_class
-
end
-
-
desc "Omniture Variables"
-
tag "omniture_vars" do |tag|
-
domain = "#{request.protocol}#{request.host}"
-
if tag.locals.page.breadcrumb
-
%{<script language="JavaScript" type="text/javascript"><!--
-
s.pageName="#{domain}:#{tag.locals.page.breadcrumb}";
-
s.channel="#{domain}:#{tag.locals.page.breadcrumb}";
-
s.server="#{domain}";
-
var s_code=s.t();
-
//--></script>}
-
end
-
end
-
-
def get_content(page, type)
-
if page.field(type) && !page.field(type).content.blank?
-
CGI.escapeHTML(page.field(type).content)
-
end
-
-
end
-
-
end
-
-
module Tags::NavigationTags
-
include TrustyCms::Taggable
-
-
-
desc %{One Column Subnavigation Tag
-
-
*Usage:*
-
<pre><r:subnav_one_column /></pre>
-
}
-
tag "subnav_one_column" do |tag|
-
request.env["action_controller.instance"].render_to_string :partial => "navigation/subnav",
-
:locals => {
-
:subnav_class => 'subnav-one-column',
-
:current_page => tag.locals.page,
-
:top_level_page => top_level_page(tag.locals.page)}
-
end
-
-
desc %{Two Column Subnavigation Tag
-
-
*Usage:*
-
<pre><r:subnav_two_column /></pre>
-
}
-
tag "subnav_two_column" do |tag|
-
request.env["action_controller.instance"].render_to_string :partial => "navigation/subnav",
-
:locals => {
-
:subnav_class => 'subnav-two-column',
-
:current_page => tag.locals.page,
-
:top_level_page => top_level_page(tag.locals.page)}
-
end
-
-
desc %{Three Column Subnavigation Tag
-
-
*Usage:*
-
<pre><r:subnav_three_column /></pre>
-
-
}
-
tag "subnav_three_column" do |tag|
-
-
request.env["action_controller.instance"].render_to_string :partial => "navigation/subnav",
-
:locals => {
-
:subnav_class => 'subnav-three-column',
-
:current_page => tag.locals.page,
-
:top_level_page => top_level_page(tag.locals.page)}
-
end
-
-
-
def top_level_page(page)
-
page = page.parent while page.parent.slug != '/'
-
page
-
end
-
-
def show_detail(show_detail)
-
if show_detail
-
return show_detail.downcase == "true" ? true : false
-
end
-
end
-
-
end
-
-
module Tags::SocialFeedTags
-
include TrustyCms::Taggable
-
-
desc %{Instagram posts feed
-
-
*Usage:*
-
<pre><code><r:instagram_posts tag="culturaltrust">/code></pre>}
-
tag "instagram_posts" do |tag|
-
posts = Rails.cache.fetch("instagram_posts/#{tag.attr['tag']}", expires_in: 5.minutes) do
-
InstagramFeedService.new.get_feed_for_tag(tag.attr['tag'])
-
end
-
request.env["action_controller.instance"].render_to_string :partial => "social/instagram_posts",
-
:locals => {:posts => posts}
-
-
end
-
-
desc %{Twitter posts feed
-
-
*Usage:*
-
<pre><code><r:twitter_posts tag="culturaltrust">/code></pre>}
-
tag "twitter_posts" do |tag|
-
posts = Rails.cache.fetch("twitter_posts/#{tag.attr['tag']}", expires_in: 5.minutes) do
-
TwitterFeedService.new.get_feed_for_tag(tag.attr['tag'])
-
end
-
request.env["action_controller.instance"].render_to_string :partial => "social/twitter_posts",
-
:locals => {:posts => posts}
-
-
end
-
-
end
-
require "active_record"
-
-
class ActiveRecord::Base
-
def self.create_or_update_for_site(options = {}, key = :name)
-
options["site"] = Site.find(:first, :conditions => {:name => options["site"]})
-
Page.current_site = options["site"]
-
create_or_update options, key
-
end
-
-
def self.create_or_update_for_sites(options = {}, key = :name)
-
options["sites"] = options["sites"].collect { |site_name| Site.find(:first, :conditions => {:name => site_name}) }
-
create_or_update options, key
-
end
-
-
def self.create_or_update(options = {}, key = :id)
-
record_from_db = find(:first, :conditions=>{key => options[key.to_s]})
-
return record_from_db if record_from_db
-
options.delete "overwrite"
-
record = record_from_db || new
-
record.id = options["id"] if options["id"]
-
record.update_attributes!(options)
-
record
-
end
-
-
def existing_record?
-
(not id.nil?)
-
end
-
-
def create_or_update_with_attributes! attributes
-
puts attributes
-
#return if ConvoySeedUtil.create_only && existing_record?
-
return if existing_record?
-
update_attributes!(attributes)
-
end
-
end
-
module TrustyFestivityExtension
-
VERSION = "2.5.7"
-
SUMMARY = "Festival microsite engine for Trusty CMS"
-
DESCRIPTION = "Event management for arts festivals."
-
URL = "http://github.com/pgharts/trusty-festivity-extension"
-
AUTHORS = ["Eric Sipple, Danielle Greaves, Brittany Martin, Patrick FitzGerald"]
-
EMAIL = ["fitzgerald@trustarts.org"]
-
end