Class: TicketsController

Inherits:
ArtfullyOseController show all
Defined in:
app/controllers/tickets_controller.rb

Instance Method Summary collapse

Instance Method Details

#bulk_editObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'app/controllers/tickets_controller.rb', line 101

def bulk_edit
  authorize! :bulk_edit, Ticket
  @show = Show.find(params[:show_id])
  @selected_tickets = params[:selected_tickets]

  if @selected_tickets.nil?
    flash[:error] = "No tickets were selected"
    redirect_to event_show_url(@show.event, @show) and return
  elsif 'Update Price' == params[:commit]
      set_new_price
  else
    with_confirmation do
      bulk_edit_tickets(@show, @selected_tickets, params[:commit])
      redirect_to event_show_url(@show.event, @show) and return
    end
  end
end

#change_pricesObject



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'app/controllers/tickets_controller.rb', line 133

def change_prices
  @grouped_tickets = params[:grouped_tickets]

  with_confirmation_price_change do
    @selected_tickets = params[:selected_tickets]
    @price = params[:price]
    @show = Show.find(params[:show_id])

    if @show.bulk_change_price(@selected_tickets, @price)
      flash[:notice] = "Updated the price of #{to_plural(@selected_tickets.size, 'ticket')}. "
    else
      flash[:error] = "Tickets that have been sold or comped can't be given a new price."
    end

    redirect_to event_show_url(@show.event, @show) and return
  end
end

#createObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/tickets_controller.rb', line 41

def create
  @show = Show.find(params[:show_id])
  @section = Section.find(params[:section_id])
  @quantity = params[:quantity].to_i
  @on_sale = params[:on_sale] == "true"

  if @quantity > 1000
    flash[:error] = "You cannot add more than 1000 tickets at a time."
    redirect_to event_show_path(@show.event, @show)    
  elsif @quantity > 0
    result = Ticket.create_many(@show, @section, @quantity, @on_sale)
    flash[:notice] = "Successfully added #{to_plural(@quantity, 'tickets')}."
    redirect_to event_show_path(@show.event, @show)
  else
    flash[:error] = "Enter a number greater than 0 to add tickets to the show."
    redirect_to event_show_path(@show.event, @show)
  end
end

#deleteObject



88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/controllers/tickets_controller.rb', line 88

def delete
  @show = Show.find(params[:show_id])
  @selected_tickets = params[:selected_tickets]
  with_confirmation do
    if @show.bulk_delete(@selected_tickets)
      flash[:notice] = "Deleted #{to_plural(@selected_tickets.size, 'ticket')}. "
    else
      flash[:error] = "Tickets that have been sold or comped can't be put on or taken off sale. A ticket that is already on sale or off sale can't be put on or off sale again."
    end
    redirect_to event_show_url(@show.event, @show)
  end
end

#newObject



8
9
10
11
12
13
14
# File 'app/controllers/tickets_controller.rb', line 8

def new
  @show = Show.find(params[:show_id])
  when_section_selected do
    @section = Section.find(params[:section_id])
    @summary = @section.summarize
  end 
end

#off_saleObject



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/tickets_controller.rb', line 74

def off_sale
  authorize! :bulk_edit, Ticket
  with_confirmation do
    @show = Show.find(params[:show_id])
    @selected_tickets = params[:selected_tickets]
    if @show.bulk_off_sale(@selected_tickets)
      flash[:notice] = "Put #{to_plural(@selected_tickets.size, 'ticket')} off sale. "
    else
      flash[:error] = "Tickets that have been sold or comped can't be put on or taken off sale. A ticket that is already on sale or off sale can't be put on or off sale again."
    end
    redirect_to event_show_url(@show.event, @show)
  end
end

#on_saleObject



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/tickets_controller.rb', line 60

def on_sale
  authorize! :bulk_edit, Ticket
  with_confirmation do
    @show = Show.find(params[:show_id])
    @selected_tickets = params[:selected_tickets]
    if @show.bulk_on_sale(@selected_tickets)
      flash[:notice] = "Put #{to_plural(@selected_tickets.size, 'ticket')} on sale. "
    else
      flash[:error] = "Tickets that have been sold or comped can't be put on or taken off sale. A ticket that is already on sale or off sale can't be put on or off sale again."
    end
    redirect_to event_show_url(@show.event, @show)
  end
end

#set_new_priceObject



119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'app/controllers/tickets_controller.rb', line 119

def set_new_price
  @show = Show.find(params[:show_id])
  unless @show.event.is_free == "true"
    @selected_tickets = params[:selected_tickets]
    tix = @selected_tickets.collect{|id| Ticket.find( id )}
    sections = tix.group_by(&:section)
    @grouped_tickets = Hash[ sections.collect{ |name, tix| [name, tix.group_by(&:price)] } ]
    render 'tickets/set_new_price' and return
  else
    flash[:alert] = "You cannot change the ticket prices of a free event."
    redirect_to event_show_url(@show.event, @show) and return
  end
end

#unvalidatedObject



24
25
26
27
28
29
30
# File 'app/controllers/tickets_controller.rb', line 24

def unvalidated
  authorize! :edit, Ticket
  Ticket.find(params[:id]).unvalidate_ticket!
  respond_to do |format|
    format.json { head :ok }
  end
end

#validatedObject



16
17
18
19
20
21
22
# File 'app/controllers/tickets_controller.rb', line 16

def validated
  authorize! :edit, Ticket
  Ticket.find(params[:id]).validate_ticket!(current_user)
  respond_to do |format|
    format.json { head :ok }
  end
end

#when_section_selectedObject



32
33
34
35
36
37
38
39
# File 'app/controllers/tickets_controller.rb', line 32

def when_section_selected
  if !params[:section_id].blank?
    yield
  elsif @show.chart.sections.length == 1
    params[:section_id] = @show.chart.sections.first.id
    yield
  end
end