social_stream-events 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data/GPL Affero license +663 -0
  2. data/Gemfile +9 -0
  3. data/README.rdoc +6 -0
  4. data/Rakefile +29 -0
  5. data/app/assets/images/btn/btn_certificate.png +0 -0
  6. data/app/assets/images/btn/btn_certificates.png +0 -0
  7. data/app/assets/images/btn/btn_edit.png +0 -0
  8. data/app/assets/images/btn/btn_embebed.png +0 -0
  9. data/app/assets/images/btn/btn_event.png +0 -0
  10. data/app/assets/images/btn/btn_outline.png +0 -0
  11. data/app/assets/images/btn/event.png +0 -0
  12. data/app/assets/images/btn/flyer.png +0 -0
  13. data/app/assets/images/btn/keynote.png +0 -0
  14. data/app/assets/images/btn/live.png +0 -0
  15. data/app/assets/images/btn/time.png +0 -0
  16. data/app/assets/images/btn/trash.png +0 -0
  17. data/app/assets/images/icons/IconsByGlyphish.txt +1 -0
  18. data/app/assets/images/icons/down.png +0 -0
  19. data/app/assets/images/icons/search.png +0 -0
  20. data/app/assets/images/icons/up.png +0 -0
  21. data/app/assets/images/logos/actor/event.png +0 -0
  22. data/app/assets/images/logos/contact/event.png +0 -0
  23. data/app/assets/images/logos/original/event.png +0 -0
  24. data/app/assets/images/logos/profile/event.png +0 -0
  25. data/app/assets/images/logos/representation/event.png +0 -0
  26. data/app/assets/images/tab_bottom.png +0 -0
  27. data/app/assets/javascripts/schedule.js +123 -0
  28. data/app/assets/javascripts/settings.js +20 -0
  29. data/app/assets/javascripts/social_stream-events.js +5 -0
  30. data/app/assets/stylesheets/activities.css +4 -0
  31. data/app/assets/stylesheets/fullcalendar.css +621 -0
  32. data/app/assets/stylesheets/fullcalendar.print.css +61 -0
  33. data/app/assets/stylesheets/settings.css +4 -0
  34. data/app/assets/stylesheets/social_stream-events.css +262 -0
  35. data/app/assets/stylesheets/tie.css +4 -0
  36. data/app/assets/stylesheets/users.css +4 -0
  37. data/app/controllers/activities_controller.rb +42 -0
  38. data/app/controllers/agendas_controller.rb +54 -0
  39. data/app/controllers/calendar_events_controller.rb +157 -0
  40. data/app/controllers/events_controller.rb +85 -0
  41. data/app/controllers/sessions_controller.rb +133 -0
  42. data/app/controllers/settings_controller.rb +70 -0
  43. data/app/helpers/event_helper.rb +12 -0
  44. data/app/models/agenda.rb +55 -0
  45. data/app/models/calendar_event.rb +191 -0
  46. data/app/models/calendar_event_series.rb +126 -0
  47. data/app/models/event.rb +131 -0
  48. data/app/models/session.rb +22 -0
  49. data/app/views/activities/_activity.html.erb +5 -0
  50. data/app/views/activities/_child.html.erb +18 -0
  51. data/app/views/activities/_comments.html.erb +3 -0
  52. data/app/views/activities/_index.html.erb +95 -0
  53. data/app/views/activities/_new.html.erb +29 -0
  54. data/app/views/activities/_options.html.erb +15 -0
  55. data/app/views/activities/_root.html.erb +37 -0
  56. data/app/views/activities/_wall.html.erb +5 -0
  57. data/app/views/activities/_walls.html.erb +34 -0
  58. data/app/views/activities/documents.js.erb +1 -0
  59. data/app/views/activities/index.js.erb +1 -0
  60. data/app/views/agendas/_agenda.html.erb +1 -0
  61. data/app/views/agendas/_edit.html.erb +136 -0
  62. data/app/views/agendas/_schedule.html.erb +19 -0
  63. data/app/views/agendas/_show.html.erb +81 -0
  64. data/app/views/agendas/_show_day.html.erb +6 -0
  65. data/app/views/agendas/edit.html.erb +24 -0
  66. data/app/views/agendas/event.html.erb +1 -0
  67. data/app/views/agendas/index.html.erb +0 -0
  68. data/app/views/agendas/show.html.erb +25 -0
  69. data/app/views/calendar_events/_calendar.html.erb +0 -0
  70. data/app/views/calendar_events/_edit_form.html.erb +58 -0
  71. data/app/views/calendar_events/_form.html.erb +65 -0
  72. data/app/views/calendar_events/available.html.erb +81 -0
  73. data/app/views/calendar_events/create.js.erb +18 -0
  74. data/app/views/calendar_events/edit.js.erb +1 -0
  75. data/app/views/calendar_events/index.html.erb +162 -0
  76. data/app/views/calendar_events/move.js.erb +0 -0
  77. data/app/views/calendar_events/new.js.erb +9 -0
  78. data/app/views/calendar_events/resize.js.erb +0 -0
  79. data/app/views/calendar_events/schedule.html.erb +143 -0
  80. data/app/views/documents/_mediawall.html.erb +111 -0
  81. data/app/views/events/_event.html.erb +10 -0
  82. data/app/views/events/_fields.html.erb +5 -0
  83. data/app/views/events/_form.html.erb +12 -0
  84. data/app/views/events/_jquery.html.erb +125 -0
  85. data/app/views/events/_manage.html.erb +35 -0
  86. data/app/views/events/_new.html.erb +2 -0
  87. data/app/views/events/_sessions_edit.html.erb +46 -0
  88. data/app/views/events/_sidebar_cloud.html.erb +27 -0
  89. data/app/views/events/_sidebar_index.html.erb +1 -0
  90. data/app/views/events/_sidebar_show.html.erb +5 -0
  91. data/app/views/events/agendas.html +1 -0
  92. data/app/views/events/edit.html.erb +12 -0
  93. data/app/views/events/index.html.erb +30 -0
  94. data/app/views/events/manage.html.erb +69 -0
  95. data/app/views/events/manage.js.erb +1 -0
  96. data/app/views/events/show.html.erb +34 -0
  97. data/app/views/kaminari/_first_page.html.erb +11 -0
  98. data/app/views/kaminari/_gap.html.erb +8 -0
  99. data/app/views/kaminari/_last_page.html.erb +11 -0
  100. data/app/views/kaminari/_next_page.html.erb +11 -0
  101. data/app/views/kaminari/_page.html.erb +12 -0
  102. data/app/views/kaminari/_paginator.html.erb +23 -0
  103. data/app/views/kaminari/_prev_page.html.erb +11 -0
  104. data/app/views/profiles/_outline.html.erb +81 -0
  105. data/app/views/profiles/_profile.html.erb +40 -0
  106. data/app/views/sessions/_form.html.erb +41 -0
  107. data/app/views/sessions/_new.html.erb +63 -0
  108. data/app/views/sessions/_session.html.erb +1 -0
  109. data/app/views/sessions/_show.html.erb +27 -0
  110. data/app/views/sessions/create.html.erb +3 -0
  111. data/app/views/sessions/create.js.erb +1 -0
  112. data/app/views/sessions/destroy.js.erb +2 -0
  113. data/app/views/sessions/edit.html.erb +27 -0
  114. data/app/views/sessions/index.html.erb +1 -0
  115. data/app/views/sessions/index.js.erb +1 -0
  116. data/app/views/sessions/new.html.erb +27 -0
  117. data/app/views/settings/_contacto.html.erb +24 -0
  118. data/app/views/settings/_header.html.erb +8 -0
  119. data/app/views/settings/_index.html.erb +16 -0
  120. data/app/views/settings/_manage.html.erb +25 -0
  121. data/app/views/settings/_settings.html.erb +49 -0
  122. data/app/views/settings/delete_relation.js.erb +3 -0
  123. data/app/views/settings/index.html.erb +38 -0
  124. data/app/views/settings/manage.html.erb +31 -0
  125. data/app/views/settings/show.html.erb +15 -0
  126. data/app/views/settings/update_relation.js.erb +1 -0
  127. data/app/views/toolbar/_home.html.erb +11 -0
  128. data/app/views/toolbar/_logo.html.erb +23 -0
  129. data/app/views/toolbar/_organizer.html.erb +25 -0
  130. data/app/views/toolbar/_profile.html.erb +21 -0
  131. data/app/views/toolbar/_sponsor.html.erb +18 -0
  132. data/app/views/toolbar/_suscribed.html.erb +17 -0
  133. data/app/views/users/_index.html.erb +33 -0
  134. data/app/views/users/index.html.erb +46 -0
  135. data/config/locales/en.yml +97 -0
  136. data/config/routes.rb +46 -0
  137. data/db/20110615143707_create_social_stream_events.rb +54 -0
  138. data/lib/generators/social_stream/events/install_generator.rb +24 -0
  139. data/lib/social_stream-events.rb +15 -0
  140. data/lib/social_stream/events/engine.rb +8 -0
  141. data/lib/social_stream/migrations/events.rb +25 -0
  142. data/social_stream-events.gemspec +22 -0
  143. data/vendor/assets/javascripts/fullcalendar.js +5208 -0
  144. data/vendor/assets/javascripts/gcal.js +112 -0
  145. metadata +272 -0
@@ -0,0 +1,85 @@
1
+ class EventsController < InheritedResources::Base
2
+ # Set group founder to current_subject
3
+ # Must do before authorization
4
+ #before_filter :authenticate_user!
5
+
6
+ before_filter :set_founder, :only => :create
7
+
8
+ #load_and_authorize_resource
9
+
10
+ respond_to :html, :js
11
+
12
+ def create
13
+ create! do |success, failure|
14
+ success.html {
15
+ self.current_subject = @event
16
+ redirect_to [current_subject, :profile]
17
+ }
18
+
19
+ end
20
+
21
+ end
22
+
23
+ def edit
24
+ @event = Event.find(params[:id])
25
+
26
+ end
27
+
28
+ def index
29
+ @events = Event.most(params[:most]).
30
+ alphabetic.
31
+ letter(params[:letter]).
32
+ search(params[:search]).
33
+ tagged_with(params[:tag]).
34
+ page(params[:page]).per(10)
35
+ end
36
+
37
+ def manage
38
+ if params[:live].nil?
39
+ @events = Event.
40
+ most(params[:most]).
41
+ alphabetic.letter(params[:letter]).
42
+ search(params[:search]).
43
+ tagged_with(params[:tag]).
44
+ page(params[:page]).per(10)
45
+ else
46
+ @events = Event.
47
+ live_events().
48
+ alphabetic.letter(params[:letter]).
49
+ search(params[:search]).
50
+ tagged_with(params[:tag]).
51
+ page(params[:page]).per(10)
52
+ #@groups = Group.most(params[:most]).
53
+ # alphabetic.
54
+ # letter(params[:letter]).
55
+ # search(params[:search]).
56
+ # tagged_with(params[:tag]).
57
+ # page(params[:page]).per(10)
58
+ end
59
+ index! do |format|
60
+ format.html { render :layout => (user_signed_in? ? 'application' : 'frontpage') }
61
+ end
62
+ end
63
+
64
+ def outline
65
+
66
+ end
67
+
68
+ protected
69
+
70
+ # Overwrite resource method to support slug
71
+ # See InheritedResources::BaseHelpers#resource
72
+ def resource
73
+ @event ||= end_of_association_chain.find_by_slug!(params[:id])
74
+ end
75
+
76
+ private
77
+
78
+ def set_founder
79
+ return unless user_signed_in?
80
+
81
+ params[:event] ||= {}
82
+ params[:event][:_founder] ||= current_subject.slug
83
+ end
84
+
85
+ end
@@ -0,0 +1,133 @@
1
+ class SessionsController < InheritedResources::Base
2
+
3
+ before_filter :authenticate_user!
4
+
5
+ def new
6
+ @event= Event.find_by_id(params[:id])
7
+ @session= Session.new
8
+
9
+ end
10
+
11
+ def edit
12
+ @event= Event.find_by_id(params[:id_event])
13
+ @session= Session.find_by_id(params[:id])
14
+
15
+ end
16
+
17
+ def update
18
+ @event = Event.find_by_id(params[:id_event])
19
+ params[:session][:agenda_id]=@event.agenda.id
20
+ @session = Session.find_by_id(params[:id])
21
+ @session.update_attributes(params[:session])
22
+ # @session = Session.new (params[:session])
23
+ # @session.save
24
+ if @event.start_at.nil?
25
+ @event.start_at = @session.start_at
26
+ @event.end_at = @session.end_at
27
+ @event.save
28
+ else
29
+ if @event.start_at > @session.start_at
30
+ @event.start_at = @session.start_at
31
+ end
32
+ if @event.end_at < @session.end_at
33
+ @event.end_at = @session.end_at
34
+ end
35
+ @event.save
36
+ end
37
+ redirect_to "/agendas/"+@event.slug
38
+ end
39
+
40
+ def create
41
+ @event = Event.find_by_id(params[:event_id])
42
+ params[:session][:agenda_id]=@event.agenda.id
43
+ @session = Session.new (params[:session])
44
+ @session.save
45
+
46
+ if @event.start_at.nil?
47
+ @event.start_at = @session.start_at
48
+ @event.end_at = @session.end_at
49
+ @event.save
50
+ else
51
+ if @event.start_at > @session.start_at
52
+ @event.start_at = @session.start_at
53
+ end
54
+ if @event.end_at < @session.end_at
55
+ @event.end_at = @session.end_at
56
+ end
57
+ @event.save
58
+ end
59
+ # render :json => @session
60
+ redirect_to "/agendas/"+@event.slug
61
+ end
62
+
63
+ def index
64
+ @event = Event.find_by_slug(params[:event_id])
65
+ respond_to do |format|
66
+ format.html
67
+ end
68
+ end
69
+
70
+ def move
71
+ @session = Session.find_by_id(params[:id])
72
+ if @session
73
+ @session.start_at = (params[:minute_delta].to_i).minutes.from_now((params[:day_delta].to_i).days.from_now(@session.start_at))
74
+ @session.end_at = (params[:minute_delta].to_i).minutes.from_now((params[:day_delta].to_i).days.from_now(@session.end_at))
75
+ @session.save
76
+ end
77
+
78
+ if @event.start_at.nil?
79
+ @event.start_at = @session.start_at
80
+ @event.end_at = @session.end_at
81
+ @event.save
82
+ else
83
+ if @event.start_at > @session.start_at
84
+ @event.start_at = @session.start_at
85
+ end
86
+ if @event.end_at < @session.end_at
87
+ @event.end_at = @session.end_at
88
+ end
89
+ @event.save
90
+ end
91
+
92
+ render :json => @session
93
+ end
94
+
95
+ def resize
96
+ @session = Session.find(params[:id])
97
+ if @session
98
+ @session.end_at = (params[:minute_delta].to_i).minutes.from_now((params[:day_delta].to_i).days.from_now(@session.end_at))
99
+ @session.save
100
+ end
101
+ end
102
+
103
+
104
+ def destroy
105
+ @session = Session.find(params[:id])
106
+ @event = @session.event
107
+ start_at=@session.start_at
108
+ end_at=@session.end_at
109
+ @session.destroy
110
+
111
+ if !@event.start_at.nil?
112
+ if start_at < @event.start_at
113
+ #changing the start_at of the event
114
+ @event.start_at = @event.sessions.order("start_at ASC").map{|x| x.start_at}.first
115
+ end
116
+ if end_at > @event.end_at
117
+ #changing the end_at of the event
118
+ @event.end_at = @event.sessions.order("end_at DESC").map{|x| x.end_at}.first
119
+ end
120
+ @event.save
121
+ end
122
+ redirect_to "/agendas/"+@event.slug
123
+ end
124
+
125
+
126
+ def show
127
+ @event = Event.find_by_slug(params[:id])
128
+
129
+ end
130
+
131
+
132
+
133
+ end
@@ -0,0 +1,70 @@
1
+ class SettingsController < InheritedResources::Base
2
+
3
+ respond_to :html, :js
4
+ #before_filter :authenticate_user!
5
+ def show
6
+
7
+ end
8
+
9
+ def manage
10
+
11
+ # @cs_ = Actor.joins('INNER JOIN contacts ON contacts.receiver_id = actors.id INNER JOIN ties ON ties.contact_id = contacts.id INNER JOIN relations ON relations.id = ties.relation_id').where(:subject_type => ['User', 'Group', 'Event'], :contacts=>{:sender_id => current_subject}, :relations=>{:type => 'Relation::Custom'}).page(params[:page]).per(10)
12
+
13
+ @cs = current_subject.contact_subjects(:direction => :sent)
14
+ @cs = Kaminari.paginate_array(@cs).page(params[:page]).per(10)
15
+ # @cs_page = Paginator.new(self, cs.length, 10, 1)
16
+ # @offset = 0
17
+ # @cs= cs[offset..(offset + 10 -1)]
18
+
19
+ end
20
+
21
+ def delete_relation
22
+ @receiver = Actor.find params[:id]
23
+ logger.info "antes del each"
24
+ contact=Contact.where(["sender_id="+current_subject.id.to_s+" and receiver_id="+@receiver.id.to_s])
25
+ logger.info "cs:"+current_subject.name+"receiver:"+@receiver.name
26
+ tie_to_delete=contact.first.ties
27
+ logger.info "antes del if"
28
+ tie_x=tie_to_delete.first
29
+ if tie_x != nil
30
+ tie_x.destroy
31
+ end
32
+ @cs = current_subject.contact_subjects(:direction => :sent)
33
+ @cs = Kaminari.paginate_array(@cs).page(params[:page]).per(10)
34
+ respond_to do |format|
35
+ format.js {render :layout => false}
36
+ end
37
+ # redirect_to "/settings/manage"
38
+ end
39
+
40
+ def update_relation
41
+ @receiver = Actor.find params[:id]
42
+ relations = params['manage']
43
+ logger.info "antes del each"
44
+ relations.each do |x,y|
45
+ relation_id = y
46
+ contacto=Contact.where(["sender_id="+current_subject.id.to_s+" and receiver_id="+@receiver.id.to_s])
47
+ logger.info "cs:"+current_subject.name+"receiver:"+@receiver.name
48
+ tie_a_editar=contacto.first.ties
49
+ logger.info "antes del if"
50
+ tie_x=tie_a_editar.first
51
+ if tie_x != nil
52
+ logger.info "dentro del if"
53
+ tie_x.relation_id=relation_id
54
+ tie_x.save
55
+ logger.info "luego del save"
56
+ else
57
+ logger.info "dentro del else"
58
+ nuevo_tie=Tie.new
59
+ nuevo_tie.contact_id=contacto.first.id
60
+ nuevo_tie.relation_id=relation_id
61
+ nuevo_tie.save
62
+ end
63
+ end
64
+ respond_to do |format|
65
+ format.js {render :layout => false}
66
+ end
67
+
68
+ # redirect_to "/settings/manage"
69
+ end
70
+ end
@@ -0,0 +1,12 @@
1
+ module EventHelper
2
+
3
+ def wrap_file_name(name)
4
+ name
5
+ if(name.length > 12)
6
+ name[0,12]+"..."
7
+ end
8
+ end
9
+
10
+
11
+
12
+ end
@@ -0,0 +1,55 @@
1
+ class Agenda < ActiveRecord::Base
2
+ include SocialStream::Models::Object
3
+
4
+ belongs_to :event
5
+ has_many :sessions, :dependent => :destroy
6
+
7
+ validates_presence_of :event_id
8
+
9
+ # Fullcalendar slot values
10
+ SLOT_VALUES=[5,15,30]
11
+
12
+ =begin
13
+ def to_fullcalendar_json
14
+ sessions.map(&:to_fullcalendar_json).join(", ")
15
+
16
+ "[#{sessions.map(&:to_fullcalendar_json).join(", ")}]"
17
+ end
18
+ =end
19
+
20
+
21
+ def start_date
22
+ event.start_at
23
+ end
24
+
25
+ def end_date
26
+ event.end_at
27
+ end
28
+
29
+ def getSessions(id,time_start,time_end)
30
+ @sessions = sessions.where( "start_at >= '#{time_start.to_formatted_s(:db)}' AND
31
+ end_at <= '#{time_end.to_formatted_s(:db)}' ")
32
+ end
33
+
34
+ def contents_for_day(i)
35
+
36
+ @sessions = sessions.where(
37
+ "start_at >= :day_start AND start_at < :day_end", {:day_start => start_date.to_date + (i-1).day,
38
+ :day_end => start_date.to_date + i.day})
39
+
40
+
41
+ end
42
+
43
+ def self.next_time_slot_for_drop_down
44
+ if Time.zone.now.min > 40
45
+ Time.zone.parse("#{Time.zone.now.hour + 1}:00")
46
+ else
47
+ Time.zone.parse("#{Time.zone.now.hour}:#{(Time.zone.now.min.to_f/SLOT_VALUES[1]).ceil*SLOT_VALUES[1]}")
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+
54
+
55
+
@@ -0,0 +1,191 @@
1
+ # == Schema Information
2
+ # Schema version: 20100330111833
3
+ #
4
+ # Table name: events
5
+ #
6
+ # id :integer(4) not null, primary key
7
+ # title :string(255)
8
+ # starttime :datetime
9
+ # endtime :datetime
10
+ # all_day :boolean(1)
11
+ # created_at :datetime
12
+ # updated_at :datetime
13
+ # description :text
14
+ # event_series_id :integer(4)
15
+ #
16
+
17
+ class CalendarEvent < ActiveRecord::Base
18
+ attr_accessor :period, :frequency, :commit_button
19
+
20
+ validates_presence_of :title, :description
21
+
22
+ belongs_to :calendar_event_series
23
+
24
+ belongs_to :object, :polymorphic => true
25
+
26
+ named_scope :object_type, lambda { |type|
27
+ type ?
28
+ { :conditions => [ "object_type = ?", type.to_s.classify ] } :
29
+ {}
30
+ }
31
+
32
+ REPEATS = [
33
+ ["No repetir", "Does not repeat"],
34
+ # ["Diariamente", "Daily" ],
35
+ ["Semanalmente", "Weekly" ]
36
+ # ["Mensualmente", "Monthly" ],
37
+ # ["Anualmente", "Yearly" ]
38
+ ]
39
+
40
+ def validate
41
+ if (starttime >= endtime) and !all_day
42
+ errors.add_to_base("Inicio debe ser menor que Fin")
43
+ end
44
+ end
45
+
46
+ def update_calendar_events(events, event)
47
+ events.each do |e|
48
+ begin
49
+ st, et = e.starttime, e.endtime
50
+ e.attributes = event
51
+ if calendar_event_series.period.downcase == 'monthly' or calendar_event_series.period.downcase == 'yearly'
52
+ nst = DateTime.parse("#{e.starttime.hour}:#{e.starttime.min}:#{e.starttime.sec}, #{e.starttime.day}-#{st.month}-#{st.year}")
53
+ net = DateTime.parse("#{e.endtime.hour}:#{e.endtime.min}:#{e.endtime.sec}, #{e.endtime.day}-#{et.month}-#{et.year}")
54
+ else
55
+ nst = DateTime.parse("#{e.starttime.hour}:#{e.starttime.min}:#{e.starttime.sec}, #{st.day}-#{st.month}-#{st.year}")
56
+ net = DateTime.parse("#{e.endtime.hour}:#{e.endtime.min}:#{e.endtime.sec}, #{et.day}-#{et.month}-#{et.year}")
57
+ end
58
+ #puts "#{nst} ::::::::: #{net}"
59
+ rescue
60
+ nst = net = nil
61
+ end
62
+ if nst and net
63
+ # e.attributes = event
64
+ e.starttime, e.endtime = nst, net
65
+ e.save
66
+ end
67
+ end
68
+
69
+ calendar_event_series.attributes = event
70
+ calendar_event_series.save
71
+ end
72
+
73
+ #method to know if an event happens in the future
74
+ def future?
75
+ return has_date? && starttime.future?
76
+ end
77
+
78
+
79
+ #method to know if an event happens in the past
80
+ def past?
81
+ return has_date? && endtime.past?
82
+ end
83
+
84
+
85
+ def has_date?
86
+ starttime
87
+ end
88
+
89
+ #method to get the starting date of an event in the correct format
90
+ def get_formatted_date
91
+ has_date? ?
92
+ I18n::localize(starttime, :format => "%A, %d %b %Y #{I18n::translate('date.at')} %H:%M. #{get_formatted_timezone}") :
93
+ I18n::t('date.undefined')
94
+ end
95
+
96
+ def get_formatted_timezone
97
+ has_date? ?
98
+ "#{I18n::t('timezone.one')}: #{Time.zone.name} (#{starttime.zone}, GMT #{starttime.formatted_offset})" :
99
+ I18n::t('date.undefined')
100
+ end
101
+
102
+ #method to get the starting hour of an event in the correct format
103
+ def get_formatted_hour
104
+ has_date? ? starttime.strftime("%H:%M") : I18n::t('date.undefined')
105
+ end
106
+
107
+ def get_formatted_timezone_lite
108
+ has_date? ?
109
+ "GMT #{starttime.formatted_offset}" :
110
+ I18n::t('date.undefined')
111
+ end
112
+
113
+ def to_s
114
+ s = I18n.localize(starttime, :format => '%A %d de %B de %Y')
115
+ if (starttime.strftime('%Y-%m-%d') == endtime.strftime('%Y-%m-%d'))
116
+ s += " de " + starttime.strftime("%H:%M") + " hasta " + endtime.strftime("%H:%M") + " " + get_formatted_timezone_lite
117
+ end
118
+ #starttime.strftime '%m/%d/%Y' + ' hasta ' + endtime.strftime '%m/%d/%Y'
119
+ end
120
+
121
+ def to_string(timezone)
122
+ s = I18n.localize(starttime, :format => '%A %d de %B de %Y')
123
+ if (starttime.strftime('%Y-%m-%d') == endtime.strftime('%Y-%m-%d'))
124
+ logger.error "timezone= #{timezone}"
125
+ if (!timezone.nil? && timezone != "")
126
+ s += " de " + starttime.in_time_zone(timezone).strftime("%H:%M") + " hasta " + endtime.in_time_zone(timezone).strftime("%H:%M") + " GMT #{starttime.in_time_zone(timezone).formatted_offset}"
127
+ end
128
+ s += " (" + starttime.utc.strftime("%H:%M") + " hasta " + endtime.utc.strftime("%H:%M") + " GMT)"
129
+ end
130
+ #starttime.strftime '%m/%d/%Y' + ' hasta ' + endtime.strftime '%m/%d/%Y'
131
+ end
132
+
133
+ def in(nce)
134
+ return (starttime <= nce.starttime && endtime > nce.starttime) || (starttime < nce.endtime && endtime >= nce.endtime)
135
+ end
136
+
137
+ def self.find_room(reservation, room_id)
138
+ logger.error "reservation=#{reservation.id} room=#{room_id}"
139
+ room_object=Room.find room_id
140
+ calendar_events_roster = room_object.calendar_events
141
+ logger.error "*** calendar_series.size = #{calendar_events_roster.size}"
142
+ for iterador in calendar_events_roster
143
+ logger.error "*** iterador.id = #{iterador.id} all_day=#{iterador.all_day}"
144
+ if iterador.all_day
145
+ logger.error "#{iterador.starttime} #{iterador.endtime}"
146
+ eventos = CalendarEvent.find(:all, :conditions => ["object_type = 'Room' AND object_id=? AND ((starttime <= ? AND endtime> ?) OR (starttime< ? AND endtime>= ? ))", room_id, iterador.starttime, iterador.starttime, iterador.endtime, iterador.endtime])
147
+ logger.error "tamanio #{eventos.size}"
148
+ if eventos.size != 0
149
+ return false
150
+ end
151
+ else
152
+ logger.error "#{iterador.starttime} #{iterador.endtime}"
153
+ eventos = CalendarEvent.find(:all, :conditions => ["object_type = 'Room' AND object_id=? AND ((starttime <= ? AND endtime> ?) OR (starttime< ? AND endtime>= ? ))", room_id, iterador.starttime, iterador.starttime, iterador.endtime, iterador.endtime])
154
+ logger.error "tamanio #{eventos.size}"
155
+ if eventos.size != 0
156
+ return false
157
+ end
158
+ end
159
+ end
160
+ return true
161
+ end
162
+
163
+ def self.find_room_reserved(reservation, room_id)
164
+ logger.error "reserved reservation=#{reservation.id} room=#{room_id}"
165
+ reservations_approved = Reservation.find(:all, :conditions => ["room_id=? AND state=?", room_id, Reservation::STATE_APPROVED])
166
+ for reservation_approved in reservations_approved
167
+ calendar_events_roster = reservation_approved.calendar_events
168
+ logger.error "*** reserved calendar_series.size = #{calendar_events_roster.size}"
169
+ for iterador in calendar_events_roster
170
+ logger.error "*** reserved iterador.id = #{iterador.id} all_day=#{iterador.all_day}"
171
+ if iterador.all_day
172
+ logger.error "reserved {iterador.starttime} #{iterador.endtime}"
173
+ eventos = CalendarEvent.find(:all, :conditions => ["object_type = 'Room' AND object_id=? AND ((starttime <= ? AND endtime> ?) OR (starttime< ? AND endtime>= ? ))", room_id, iterador.starttime, iterador.starttime, iterador.endtime, iterador.endtime])
174
+ logger.error "reserved tamanio #{eventos.size}"
175
+ if eventos.size != 0
176
+ return false
177
+ end
178
+ else
179
+ logger.error "reserved #{iterador.starttime} #{iterador.endtime}"
180
+ eventos = CalendarEvent.find(:all, :conditions => ["object_type = 'Room' AND object_id=? AND ((starttime <= ? AND endtime> ?) OR (starttime< ? AND endtime>= ? ))", room_id, iterador.starttime, iterador.starttime, iterador.endtime, iterador.endtime])
181
+ logger.error "reserved tamanio #{eventos.size}"
182
+ if eventos.size != 0
183
+ return false
184
+ end
185
+ end
186
+ end
187
+ end
188
+ return true
189
+ end
190
+
191
+ end