<commit_before># Copyright 2008-2010 Universidad Politécnica de Madrid and Agora Systems S.A.
#
# This file is part of VCC (Virtual Conference Center).
#
# VCC is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# VCC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with VCC.  If not, see <http://www.gnu.org/licenses/>.

class AgendaEntriesController < ApplicationController
  before_filter :space!
  before_filter :event
  
  #before_filter :fill_start_and_end_time, :only => [:create, :update]
  
  #authorization_filter :create, :agenda_entry, :only => [ :new, :create ]
  #authorization_filter :update, :agenda_entry, :only => [ :edit, :update ]
  #authorization_filter :delete, :agenda_entry, :only => [ :destroy ]
  

  #GET /agenda_entries
  #GET /agenda_entries.xml
  #returns the agenda_entries for the days 2 to end by ajax
  def index
    @days = (0..@event.days-1).to_a
    if @event.days > 1   
      unless params[:page_shown]
        params[:page_shown]="0"
      end
      #the agenda has shown params[:page_shown], let's remove it from the pages to be shown     
      @days.delete(params[:page_shown])
    end
    respond_to do |format|
      format.html { redirect_to [ @event.space, @event ] }
      format.js
    end 
  end

  # GET /agenda_entries/1
  # GET /agenda_entries/1.xml
  def show
    @agenda_entry = AgendaEntry.find(params[:id])

    respond_to do |format|
      format.js
      format.html # show.html.erb
      format.xml  { render :xml => @agenda_entry }
    end
  end
  
  
  # GET /agenda_entries/new
  # GET /agenda_entries/new.xml
  def new
     @agenda_entry = AgendaEntry.new
     @day=params[:day]
     

  end
  
  # POST /agenda_entries
  # POST /agenda_entries.xml
  def create
    @agenda_entry = AgendaEntry.new(params[:agenda_entry])

    @agenda_entry.agenda = @event.agenda
    @agenda_entry.author = current_user
    
    respond_to do |format|
      if @agenda_entry.save
        format.html {redirect_to(space_event_path(@space, @event, :show_day=>@event.day_for(@agenda_entry), :edit_entry => @agenda_entry.id, :anchor=>"edit_entry_anchor" )) }
      else    
        flash[:notice] = t('agenda.entry.failed')
        message = ""
        @agenda_entry.errors.full_messages.each {|msg| message += msg + "  <br/>"}
        flash[:error] = message
        format.html { redirect_to(space_event_path(@space, @event)) }
      end
    end
  end
  
  # GET /agenda_entries/1/edit
  def edit
    @agenda_entry = AgendaEntry.find(params[:id])
    @day=@agenda_entry.agenda.event.day_for(@agenda_entry)
  end
  
  
  # PUT /agenda_entries/1
  # PUT /agenda_entries/1.xml
  def update
    @agenda_entry = AgendaEntry.find(params[:id])
    @agenda_entry.author = current_user
    
    respond_to do |format|
      if @agenda_entry.update_attributes(params[:agenda_entry])
        if params[:speakers] && params[:speakers][:name]
          unknown_users = create_performances_for_agenda_entry(Role.find_by_name("Speaker"), params[:speakers][:name])
          @agenda_entry.update_attribute(:speakers, unknown_users.join(", "))
        end
        flash[:notice] = t('agenda.entry.updated')
        day = @event.day_for(@agenda_entry).to_s
        format.html { redirect_to(space_event_path(@space, @event, :show_day => day) ) }
      else
        message = ""
        @agenda_entry.errors.full_messages.each {|msg| message += msg + "  <br/>"}
        flash[:error] = message
        format.html { redirect_to(space_event_path(@space, @event)) }
      end
    end
  end
  
  # DELETE /agenda_entries/1
  # DELETE /agenda_entries/1.xml
  def destroy
    @agenda_entry = AgendaEntry.find(params[:id])
    day = @event.day_for(@agenda_entry).to_s  
    respond_to do |format|
      if @agenda_entry.destroy
        flash[:notice] = t('agenda.entry.delete')
        format.html { redirect_to(space_event_path(@space, @event)) }
        format.xml  { head :ok }
      else
        message = ""
        @agenda_entry.errors.full_messages.each {|msg| message += msg + "  <br/>"}
        flash[:error] = message
        format.html { redirect_to(space_event_path(@space, @event)) }
      end
    end  
    
  end
  
  private
  
  def event
    @event = Event.find_by_permalink(params[:event_id]) || raise ActiveRecord::RecordNotFound
  end
  
  
  #in the params we receive the hour and minutes (in start_time and end_time)
  #and a param called entry_day that indicates the day of the event
  #with this method we fill the real start and end time with the full time 
  def fill_start_and_end_time 
      thedate = @event.start_date.to_date + params[:entry_day].to_i      
      params[:agenda_entry][:start_time] = thedate + params[:agenda_entry]["start_time(4i)"].to_i.hour + params[:agenda_entry]["start_time(5i)"].to_i.min
      params[:agenda_entry][:end_time] = thedate + params[:agenda_entry]["end_time(4i)"].to_i.hour + params[:agenda_entry]["end_time(5i)"].to_i.min

  end
  
  
  #this method returns an array with the users unknown
  def create_performances_for_agenda_entry(role, array_usernames)
    unknown_users = []    
    #first we delete the old ones if there were some (this is for the update operation that creates new performances in the event)
    Performance.find(:all, :conditions => {:role_id => role, :stage_id => @agenda_entry}).each do |perf| perf.delete end
    for name in array_usernames
      #if the user is in the db we create the performance, if not it is a name that we do not know, we store it in the speakers field in db<commit_msg>Fix syntax error in AgendaEntriesController<commit_after># Copyright 2008-2010 Universidad Politécnica de Madrid and Agora Systems S.A.
#
# This file is part of VCC (Virtual Conference Center).
#
# VCC is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# VCC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with VCC.  If not, see <http://www.gnu.org/licenses/>.

class AgendaEntriesController < ApplicationController
  before_filter :space!
  before_filter :event
  
  #before_filter :fill_start_and_end_time, :only => [:create, :update]
  
  #authorization_filter :create, :agenda_entry, :only => [ :new, :create ]
  #authorization_filter :update, :agenda_entry, :only => [ :edit, :update ]
  #authorization_filter :delete, :agenda_entry, :only => [ :destroy ]
  

  #GET /agenda_entries
  #GET /agenda_entries.xml
  #returns the agenda_entries for the days 2 to end by ajax
  def index
    @days = (0..@event.days-1).to_a
    if @event.days > 1   
      unless params[:page_shown]
        params[:page_shown]="0"
      end
      #the agenda has shown params[:page_shown], let's remove it from the pages to be shown     
      @days.delete(params[:page_shown])
    end
    respond_to do |format|
      format.html { redirect_to [ @event.space, @event ] }
      format.js
    end 
  end

  # GET /agenda_entries/1
  # GET /agenda_entries/1.xml
  def show
    @agenda_entry = AgendaEntry.find(params[:id])

    respond_to do |format|
      format.js
      format.html # show.html.erb
      format.xml  { render :xml => @agenda_entry }
    end
  end
  
  
  # GET /agenda_entries/new
  # GET /agenda_entries/new.xml
  def new
     @agenda_entry = AgendaEntry.new
     @day=params[:day]
     

  end
  
  # POST /agenda_entries
  # POST /agenda_entries.xml
  def create
    @agenda_entry = AgendaEntry.new(params[:agenda_entry])

    @agenda_entry.agenda = @event.agenda
    @agenda_entry.author = current_user
    
    respond_to do |format|
      if @agenda_entry.save
        format.html {redirect_to(space_event_path(@space, @event, :show_day=>@event.day_for(@agenda_entry), :edit_entry => @agenda_entry.id, :anchor=>"edit_entry_anchor" )) }
      else    
        flash[:notice] = t('agenda.entry.failed')
        message = ""
        @agenda_entry.errors.full_messages.each {|msg| message += msg + "  <br/>"}
        flash[:error] = message
        format.html { redirect_to(space_event_path(@space, @event)) }
      end
    end
  end
  
  # GET /agenda_entries/1/edit
  def edit
    @agenda_entry = AgendaEntry.find(params[:id])
    @day=@agenda_entry.agenda.event.day_for(@agenda_entry)
  end
  
  
  # PUT /agenda_entries/1
  # PUT /agenda_entries/1.xml
  def update
    @agenda_entry = AgendaEntry.find(params[:id])
    @agenda_entry.author = current_user
    
    respond_to do |format|
      if @agenda_entry.update_attributes(params[:agenda_entry])
        if params[:speakers] && params[:speakers][:name]
          unknown_users = create_performances_for_agenda_entry(Role.find_by_name("Speaker"), params[:speakers][:name])
          @agenda_entry.update_attribute(:speakers, unknown_users.join(", "))
        end
        flash[:notice] = t('agenda.entry.updated')
        day = @event.day_for(@agenda_entry).to_s
        format.html { redirect_to(space_event_path(@space, @event, :show_day => day) ) }
      else
        message = ""
        @agenda_entry.errors.full_messages.each {|msg| message += msg + "  <br/>"}
        flash[:error] = message
        format.html { redirect_to(space_event_path(@space, @event)) }
      end
    end
  end
  
  # DELETE /agenda_entries/1
  # DELETE /agenda_entries/1.xml
  def destroy
    @agenda_entry = AgendaEntry.find(params[:id])
    day = @event.day_for(@agenda_entry).to_s  
    respond_to do |format|
      if @agenda_entry.destroy
        flash[:notice] = t('agenda.entry.delete')
        format.html { redirect_to(space_event_path(@space, @event)) }
        format.xml  { head :ok }
      else
        message = ""
        @agenda_entry.errors.full_messages.each {|msg| message += msg + "  <br/>"}
        flash[:error] = message
        format.html { redirect_to(space_event_path(@space, @event)) }
      end
    end  
    
  end
  
  private
  
  def event
    @event = Event.find_by_permalink(params[:event_id]) || raise(ActiveRecord::RecordNotFound)
  end
  
  
  #in the params we receive the hour and minutes (in start_time and end_time)
  #and a param called entry_day that indicates the day of the event
  #with this method we fill the real start and end time with the full time 
  def fill_start_and_end_time 
      thedate = @event.start_date.to_date + params[:entry_day].to_i      
      params[:agenda_entry][:start_time] = thedate + params[:agenda_entry]["start_time(4i)"].to_i.hour + params[:agenda_entry]["start_time(5i)"].to_i.min
      params[:agenda_entry][:end_time] = thedate + params[:agenda_entry]["end_time(4i)"].to_i.hour + params[:agenda_entry]["end_time(5i)"].to_i.min

  end
  
  
  #this method returns an array with the users unknown
  def create_performances_for_agenda_entry(role, array_usernames)
    unknown_users = []    
    #first we delete the old ones if there were some (this is for the update operation that creates new performances in the event)
    Performance.find(:all, :conditions => {:role_id => role, :stage_id => @agenda_entry}).each do |perf| perf.delete end
    for name in array_usernames
      #if the user is in the db we create the performance, if not it is a name that we do not know, we store it in the speakers field in db
{'fraction_non_alphanumeric': 0.10911521430361767, 'fraction_numerical': 0.004177458434288578, 'mean_word_length': 3.2567567567567566, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 18}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2640459', 'n_tokens_mistral': 3938, 'n_tokens_neox': 3885, 'n_words': 1018}