Module: ConferenceManager::Models::ConferenceManagerSession::ClassMethods

Defined in:
lib/conference_manager/models/conference_manager_session.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_conference_manager_sessionObject



15
16
17
# File 'lib/conference_manager/models/conference_manager_session.rb', line 15

def acts_as_conference_manager_session
  include ConferenceManager::Models::ConferenceManagerSession::InstanceMethods
end

#included(base) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/conference_manager/models/conference_manager_session.rb', line 19

def included(base)
  base.class_eval do

    validate_on_create do |entry|

    # Validation: Session must be future
      if entry.errors.empty? && entry.event.uses_conference_manager? && entry.start_time < (Time.zone.now + WAKE_UP_TIME)
        entry.errors.add_to_base(I18n.t('agenda.entry.error.past_times',
        :min_date => I18n.l(Time.zone.now + WAKE_UP_TIME), :format => '%d %b %Y %H:%M'))
      end

      #Session creation on Conference Manager
      if entry.errors.empty? && entry.event.uses_conference_manager?

        cm_s =
        ConferenceManager::Session.new(:name => "none",
        :recording => entry.cm_recording?,
        :streaming => entry.cm_streaming?,
        :initDate=> ((entry.start_time - entry.event.start_date)*1000).to_i,
        :endDate=> ((entry.end_time - entry.event.start_date)*1000).to_i,
        :event_id => entry.event.cm_event_id)
        begin
          cm_s.save
          entry.cm_session = cm_s
        rescue => e
        entry.errors.add_to_base(e.to_s)
        end
      end
    end

    validate_on_update do |entry|

      if entry.errors.empty? && entry.event.uses_conference_manager?

        # Validation: In past sessions cannot be edited PAST_UNCHANGEABLE_ATTRIBUTES
        if entry.end_time_was.present? && entry.end_time_was.past?
          entry.errors.add_to_base(I18n.t('agenda.entry.error.attribute_unchangeable')) if (entry.changed & PAST_UNCHANGEABLE_ATTRIBUTES).any?

        # Validation: In current sessions cannot be edited CURRENT_UNCHANGEABLE_ATTRIBUTES
        elsif entry.end_time_was.present? && !(entry.end_time_was.past?) && entry.start_time_was.present? && Time.now.in_time_zone > (entry.start_time_was - WAKE_UP_TIME)
          entry.errors.add_to_base(I18n.t('agenda.entry.error.attribute_unchangeable')) if (entry.changed & CURRENT_UNCHANGEABLE_ATTRIBUTES).any?
        end
      end

      #Session update on Conference Manager
      if !entry.past? && entry.errors.empty? && entry.event.uses_conference_manager? && (((entry.changed & CM_ATTRIBUTES).any?)||(entry.date_update_action.eql?"move_event")||(entry.date_update_action.eql?"start_date"))
        if (!entry.date_update_action.eql?"move_event")
          cm_s = entry.cm_session
          new_params = { :name => entry.title,
            :recording => entry.cm_recording?,
            :streaming => entry.cm_streaming?,
            :initDate=> ((entry.start_time - entry.event.start_date)*1000).to_i,
            :endDate=> ((entry.end_time - entry.event.start_date)*1000).to_i,
            :event_id => entry.event.cm_event_id }

          if entry.cm_session?
          cm_s.load(new_params)
          else
            entry.errors.add_to_base(I18n.t('event.error.cm_connection'))
          end

          begin
            cm_s.save
          rescue => e
            if cm_s.present?
            entry.errors.add_to_base(e.to_s)
            end
          end
        end
      end
    end

    before_destroy do |entry|
    #Delete session in Conference Manager if event is not in-person
      if entry.event.uses_conference_manager?
        begin
          cm_s = entry.cm_session
          cm_s.destroy
        rescue => e
          entry.errors.add_to_base(I18n.t('agenda.entry.error.delete'))
        false
        end
      end
    end
  end
end