socialforge/app/controllers/activity_notifys_controller.rb

56 lines
1.8 KiB
Ruby
Raw Normal View History

2015-06-04 15:55:41 +08:00
class ActivityNotifysController < ApplicationController
# layout 'base_projects'#by young
# default_search_scope :messages
before_filter :find_project_by_project_id#, :find_board_if_available
# before_filter :authorize, :except => [:new, :show, :create, :index]
# accept_rss_auth :index, :show
helper :activities
2015-07-03 15:03:53 +08:00
helper :attachments
2015-06-04 15:55:41 +08:00
def index
query = nil
if @course
query = ActivityNotify.where('activity_container_id=? and activity_container_type=? and notify_to=?',@course.id,'Course',User.current.id);
else
@events_by_day = []
end
if( query != nil )
limit = 10;
@obj_count = query.count();
@obj_pages = Paginator.new @obj_count,limit,params['page']
2015-06-05 10:33:42 +08:00
list = query.order('is_read,id desc').limit(limit).offset(@obj_pages.offset).all();
2015-06-04 15:55:41 +08:00
events=[];
for item in list
2015-07-10 15:02:22 +08:00
if item.activity.nil?
next
end
2015-06-04 15:55:41 +08:00
event = item.activity;
event.set_notify_id(item.id)
event.set_notify_is_read(item.is_read)
events << event
end
@events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)}
@controller_name = 'ActivityNotifys'
end
respond_to do |format|
format.html {render :template => 'courses/show', :layout => 'base_courses'}
end
end
def chang_read_flag
if @course
if(params[:an_id] != nil )
query = ActivityNotify.where('id=? and notify_to=?',params[:an_id],User.current.id)
else
query = ActivityNotify.where('activity_container_id=? and activity_container_type=? and notify_to=? and is_read=0',@course.id,'Course',User.current.id)
end
@result = query.update_all('is_read=1');
else
@result = false;
end
respond_to do |format|
format.html{render :layout => nil}
end
end
end