diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 97434a0c9..c73a1e0fc 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1,700 +1,700 @@ -class CoursesController < ApplicationController - layout 'base_courses' - include CoursesHelper - helper :activities - helper :members - helper :words - - menu_item :overview - menu_item :feedback, :only => :feedback - menu_item :homework, :only => :homework - - menu_item l(:label_sort_by_time), :only => :index - menu_item l(:label_sort_by_active), :only => :index - menu_item l(:label_sort_by_influence), :only => :index - - before_filter :can_show_course, :except => [] - before_filter :find_course, :except => [ :index, :search,:list, :new,:join,:unjoin, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches] - before_filter :authorize_course, :only => [:show, :settings, :edit, :update, :modules, :close, :reopen, :view_homework_attaches, :course] - before_filter :authorize_course_global, :only => [:view_homework_attaches, :new,:create] - before_filter :require_admin, :only => [:copy, :archive, :unarchive, :destroy, :calendar] - before_filter :toggleCourse, only: [:finishcourse, :restartcourse] - - before_filter :require_login, :only => [:join, :unjoin] - before_filter :allow_join, :only => [:join] - - def join - if User.current.logged? - course = Course.find(params[:object_id]) - if params[:course_password] == course.password - members = [] - members << Member.new(:role_ids => [10], :user_id => User.current.id) - course.members << members - - StudentsForCourse.create(:student_id => User.current.id, :course_id => params[:object_id]) - @state = 0 - else - @state = 1 - end - end - respond_to do |format| - # format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} - format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} } - end - end - - def unjoin - if User.current.logged? - - @member = Member.where('course_id = ? and user_id = ?', params[:object_id], User.current.id) - @member.first.destroy - - joined = StudentsForCourse.where('student_id = ? and course_id = ?', User.current.id, params[:object_id]) - joined.each do |join| - join.delete - end - end - respond_to do |format| - # format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} - format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} } - end - end - - #更新课程信息 - def update - @course.safe_attributes = params[:course] - @course.time = params[:time] - @course.term = params[:term] - @course.class_period = params[:class_period] - if @course.save - if params[:course][:is_public] == '0' - course_status = CourseStatus.find_by_course_id(@course.id) - course_status.destroy if course_status - elsif params[:course][:is_public] == '1' - course_status = CourseStatus.find_by_course_id(@course.id) - course_status.destroy if course_status - course_status = CourseStatus.create(:course_id => @course.id, :grade => 0) - end - - respond_to do |format| - format.html { - flash[:notice] = l(:notice_successful_update) - redirect_to settings_course_path(@course) - } - format.api { render_api_ok } - end - else - respond_to do |format| - format.html { - settings - render :action => 'settings' - } - format.api { render_validation_errors(@course) } - end - end - end - - def new_join - @course = Course.find(params[:object_id]) - end - - # 课程搜索 - # add by nwb - def search - courses_all = Course.all_course - name = params[:name] - (redirect_to courses_path, :notice => l(:label_sumbit_empty);return) if name.blank? - @courses = courses_all.visible - if params[:name].present? - @courses_all = @courses.like(params[:name]) - else - @courses_all = @courses; - end - @course_count = @courses_all.count - @course_pages = Paginator.new @course_count, per_page_option, params['page'] - - # 课程的动态数 - @course_activity_count=Hash.new - @courses_all.each do |course| - @course_activity_count[course.id]=0 - end - - case params[:course_sort_type] - when '0' - @courses = @courses_all.order("created_at desc") - @s_type = 0 - @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - - @course_activity_count=get_course_activity @courses,@course_activity_count - - when '1' - @courses = @courses_all.order("course_ac_para desc") - @s_type = 1 - @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - - @course_activity_count=get_course_activity @courses,@course_activity_count - - when '2' - @courses = @courses_all.order("watchers_count desc") - @s_type = 2 - @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - - @course_activity_count=get_course_activity @courses,@course_activity_count - - when '3' - @course_activity_count=get_course_activity @courses_all,@course_activity_count_array - @courses=handle_course @courses_all,@course_activity_count - @s_type = 3 - @courses = @courses[@course_pages.offset, @course_pages.per_page] - - else - @s_type = 0 - @courses = @courses_all.order("created_at desc") - @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - - @course_activity_count=get_course_activity @courses,@course_activity_count - - end - - respond_to do |format| - format.html { - render :layout => 'course_base' - scope = Course - unless params[:closed] - scope = scope.active - end - } - format.atom { - courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all - render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}") - } - end - end - - def member - ## 有角色参数的才是课程,没有的就是项目 - @render_file = 'member_list' - @teachers= searchTeacherAndAssistant(@course) - @canShowCode = isCourseTeacher(User.current.id,@course) - case params[:role] - when '1' - @subPage_title = l :label_teacher_list - @members = searchTeacherAndAssistant(@course) - when '2' - @subPage_title = l :label_student_list - @members = searchStudent(@course) - else - @subPage_title = '' - @members = @course.member_principals.includes(:roles, :principal).all.sort - end - @members = paginateHelper @members - render :layout => 'base_courses' - end - - #判断指定用户是否为课程教师 - def isCourseTeacher(id) - result = false - if @teachers.find_by_user_id(id) != nil - result = true - end - result - end - - def handle_course courses, activities - course_activity_count_array=activities.values() - - course_array=[] - i=0; - courses.each do |course| - course_array[i]=course - i=i+1 - end - - courses=desc_sort_course_by_avtivity(course_activity_count_array, course_array) - - return courses - end - - def settings - @issue_custom_fields = IssueCustomField.sorted.all - @issue_category ||= IssueCategory.new - @member ||= @course.members.new - @trackers = Tracker.sorted.all - end - - def create - if User.current.user_extensions.identity - @course = Course.new - @course.extra='course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s - @course.safe_attributes = params[:course] - @course.tea_id = User.current.id - # added by bai - @course.term = params[:term] - @course.time = params[:time] - #@course.school_id = params[:occupation] - @course.school_id = User.current.user_extensions.school_id - @course.setup_time = params[:setup_time] - @course.endup_time = params[:endup_time] - @course.class_period = params[:class_period] - end - - @issue_custom_fields = IssueCustomField.sorted.all - @trackers = Tracker.sorted.all - - if User.current.user_extensions.identity == 0 - if @course.save - #unless User.current.admin? - r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first - m = Member.new(:user => User.current, :roles => [r]) - m.project_id = -1 - course = CourseInfos.new(:user_id => User.current.id, :course_id => @course.id) - #user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id) - if params[:course][:is_public] == '1' - course_status = CourseStatus.create(:course_id => @course.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :course_type => @course_tag) - end - @course.members << m - @course.course_infos << course - #end - respond_to do |format| - format.html { - flash[:notice] = l(:notice_successful_create) - if params[:continue] - redirect_to new_course_path(attrs, :course => '0') - elsif params[:course_continue] - redirect_to new_course_path(:course => '1') - else - redirect_to settings_course_path(@course, :course_type => 1) - end - } - format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) } - end - else - #@course.destroy - respond_to do |format| - format.html { render :action => 'new', :layout => 'base' } #Added by young - format.api { render_validation_errors(@course) } - end - end - end - - end - - def course - @school_id = params[:school_id] - per_page_option = 10 - if @school_id == "0" or @school_id.nil? - @courses_all = Course.active.visible. - joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id"). - else - @courses_all = Course.active.visible. - joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id"). - joins(:course_extra). - where("#{Course.table_name}.school_id = ?", @school_id) - end - - @course_count = @courses_all.count - @course_pages = Paginator.new @course_count, per_page_option, params['page'] - - #gcm activity count - - @course_activity_count=Hash.new - #count initialize - @courses_all.each do |course| - @course_activity_count[course.id]=0 - end - - #@course_activity_count=get_course_activity @courses_all,@course_activity_count - #gcm end - - - case params[:course_sort_type] - when '0' - @courses = @courses_all.order("created_on desc") - @s_type = 0 - @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - - #gcm - @course_activity_count=get_course_activity @courses,@course_activity_count - #gcmend - - when '1' - @courses = @courses_all.order("course_ac_para desc") - @s_type = 1 - @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - - #gcm - @course_activity_count=get_course_activity @courses,@course_activity_count - #gcmend - - when '2' - @courses = @courses_all.order("watchers_count desc") - @s_type = 2 - @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - - #gcm - @course_activity_count=get_course_activity @courses,@course_activity_count - #gcmend - - #gcm - when '3' - - #gcm - @course_activity_count=get_course_activity @courses_all,@course_activity_count - #gcmend - - @courses=handle_course @courses_all,@course_activity_count - @s_type = 3 - @courses = @courses[@course_pages.offset, @course_pages.per_page] - else - @s_type = 0 - @courses = @courses_all.order("created_on desc") - @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - - #gcm - @course_activity_count=get_course_activity @courses,@course_activity_count - #gcmend - - end - - respond_to do |format| - format.html { - render :layout => 'base' - } - format.api { - # @offset, @limit = api_offset_and_limit - # @course_count = Course.visible.count - # @courses = Course.visible.offset(@offset).limit(@limit).order('lft').all - } - format.atom { - courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all - render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}") - } - end - end - - - def new - @course_type = params[:course_type] ||= params[:course] - @issue_custom_fields = IssueCustomField.sorted.all - @trackers = Tracker.sorted.all - - @course = Course.new - @course.safe_attributes = params[:course] - - render :layout => 'base' - end - - - def desc_sort_course_by_avtivity(activity_count, courses) - return courses if activity_count.size<2 - (activity_count.size-2).downto(0) do |i| - (0..i).each do |j| - if activity_count[j] 'base' - } - format.atom { - courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all - render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}") - } - end - end - - def homework - @offset, @limit = api_offset_and_limit({:limit => 10}) - @bids = @course.homeworks.order('deadline DESC') - @bids = @bids.like(params[:name]) if params[:name].present? - @bid_count = @bids.count - @bid_pages = Paginator.new @bid_count, @limit, params['page'] - - @offset ||= @bid_pages.reverse_offset - unless @offset == 0 - @bids = @bids.offset(@offset).limit(@limit).all.reverse - else - limit = @bid_count % @limit - if limit == 0 - limit = 10 - end - @bids = @bids.offset(@offset).limit(limit).all.reverse - end - render :layout => 'base_courses' - end - - # 新建作业 - def new_homework - @homework = Bid.new - @homework.proportion - @homework.safe_attributes = params[:bid] - if (User.current.logged? && User.current.member_of_course?(Course.find params[:id] )) - render :layout => 'base_courses' - else - render_403 - end - - end - - - - def toggleCourse - @course_prefs = Course.find_by_extra(@course.extra) - unless (@course_prefs.teacher == User.current || User.current.admin?) - render_403 - end - end - - def get_courses - @user = User.current - membership = @user.coursememberships.all - membership.sort! {|older, newer| newer.created_on <=> older.created_on } - @memberships = [] - membership.collect { |e| - @memberships.push(e) - } - @memberships_doing = [] - @memberships_done = [] - now_time = Time.now.year - @memberships.map { |e| - end_time = e.course.get_time.year - isDone = course_endTime_timeout?(e.course) - if isDone - @memberships_done.push e - else - @memberships_doing.push e - end - } - end - - def finishcourse - yesterday = Date.today.prev_day.to_time - - @course_prefs.endup_time = yesterday - @save_flag = @course_prefs.save - get_courses - - respond_to do |format| - format.js - end - end - - - def restartcourse - day = Time.parse("3000-01-01") - - @course_prefs.endup_time = day - @save_flag = @course_prefs.save - get_courses - - respond_to do |format| - format.js { - render action:'finishcourse' - } - end - end - - def show - # try to redirect to the requested menu item - if params[:jump] && redirect_to_course_menu_item(@course, params[:jump]) - return - end - - @users_by_role = @course.users_by_role - if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id))) - @user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id) - end - - - @key = User.current.rss_key - #新增内容 - @days = Setting.activity_days_default.to_i - - if params[:from] - begin; @date_to = params[:from].to_date + 1; rescue; end - end - - has = { - "show_course_files" => true, - "show_course_news" => true, - "show_course_messages" => true, - "show_bids" => true, - "show_course_journals_for_messages" => true - } - @date_to ||= Date.today + 1 - # - @date_from = (@date_to - @days) > @course.created_at.to_date ? (@date_to - @days) : @course.created_at.to_date - #@date_from = @date_to - @days-1.years - @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id])) - # 决定显示所用用户或单个用户活动 - @activity = Redmine::Activity::Fetcher.new(User.current, :course => @course, - :with_subprojects => false, - :author => @author) - @activity.scope_select {|t| has["show_#{t}"]} - # modify by nwb - # 添加私密性判断 - if User.current.member_of_course?(@course)|| User.current.admin? - events = @activity.events(@date_from, @date_to) - else - events = @activity.events(@date_from, @date_to, :is_public => 1) - end - - # 无新动态时,显示老动态 - if events.count == 0 - if User.current.member_of_course?(@course)|| User.current.admin? - events = @activity.events - else - events = @activity.events(:is_public => 1) - end - end - - @offset, @limit = api_offset_and_limit({:limit => 10}) - @events_count = events.count - @events_pages = Paginator.new @events_count, @limit, params['page'] - @offset ||= @events_pages.offset - events = events.slice(@offset,@limit) - - @events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)} - # documents - @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' - # - @teachers= searchTeacherAndAssistant(@course) - @canShowRealName = isCourseTeacher(User.current.id,@course) - - if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id))) - @user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id) - end - - respond_to do |format| - format.html{render :layout => 'base_courses'} - format.api - end - end - - #判断指定用户是否为课程教师 - def isCourseTeacher(id,course) - result = false - user = User.find(id) - if user.nil? && user.allowed_to?(:as_teacher,course)#@teachers && @teachers.count != 0 && @teachers.find_by_user_id(id) != nil - result = true - end - result - end - - def feedback - page = params[:page] - # Find the page of the requested reply - @jours = @course.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') - @limit = 10 - if params[:r] && page.nil? - offset = @jours.count(:conditions => ["#{JournalsForMessage.table_name}.id > ?", params[:r].to_i]) - page = 1 + offset / @limit - end - - @feedback_count = @jours.count - @feedback_pages = Paginator.new @feedback_count, @limit, page - @offset ||= @feedback_pages.offset - @jour = @jours[@offset, @limit] - @state = false - respond_to do |format| - format.html{render :layout => 'base_courses'} - format.api - end - end - - - - private - - def allow_join - if course_endTime_timeout? Course.find(params[:object_id]) - respond_to do |format| - format.js { - @state = 2 - render :partial => 'set_join', - :locals => {:user => User.current, - :course => Course.find(params[:object_id]), - :object_id => params[:object_id] - } - } - end - end - end - - #验证是否显示课程 - def can_show_course - @first_page = FirstPage.where("page_type = 'project'").first - if @first_page.show_course == 2 - render_404 - end - end - - - -end +class CoursesController < ApplicationController + layout 'base_courses' + include CoursesHelper + helper :activities + helper :members + helper :words + + menu_item :overview + menu_item :feedback, :only => :feedback + menu_item :homework, :only => :homework + + menu_item l(:label_sort_by_time), :only => :index + menu_item l(:label_sort_by_active), :only => :index + menu_item l(:label_sort_by_influence), :only => :index + + before_filter :can_show_course, :except => [] + before_filter :find_course, :except => [ :index, :search,:list, :new,:join,:unjoin, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches] + before_filter :authorize_course, :only => [:show, :settings, :edit, :update, :modules, :close, :reopen, :view_homework_attaches, :course] + before_filter :authorize_course_global, :only => [:view_homework_attaches, :new,:create] + before_filter :require_admin, :only => [:copy, :archive, :unarchive, :destroy, :calendar] + before_filter :toggleCourse, only: [:finishcourse, :restartcourse] + + before_filter :require_login, :only => [:join, :unjoin] + before_filter :allow_join, :only => [:join] + + def join + if User.current.logged? + course = Course.find(params[:object_id]) + if params[:course_password] == course.password + members = [] + members << Member.new(:role_ids => [10], :user_id => User.current.id) + course.members << members + + StudentsForCourse.create(:student_id => User.current.id, :course_id => params[:object_id]) + @state = 0 + else + @state = 1 + end + end + respond_to do |format| + # format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} + format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} } + end + end + + def unjoin + if User.current.logged? + + @member = Member.where('course_id = ? and user_id = ?', params[:object_id], User.current.id) + @member.first.destroy + + joined = StudentsForCourse.where('student_id = ? and course_id = ?', User.current.id, params[:object_id]) + joined.each do |join| + join.delete + end + end + respond_to do |format| + # format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} + format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} } + end + end + + #更新课程信息 + def update + @course.safe_attributes = params[:course] + @course.time = params[:time] + @course.term = params[:term] + @course.class_period = params[:class_period] + if @course.save + if params[:course][:is_public] == '0' + course_status = CourseStatus.find_by_course_id(@course.id) + course_status.destroy if course_status + elsif params[:course][:is_public] == '1' + course_status = CourseStatus.find_by_course_id(@course.id) + course_status.destroy if course_status + course_status = CourseStatus.create(:course_id => @course.id, :grade => 0) + end + + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_update) + redirect_to settings_course_path(@course) + } + format.api { render_api_ok } + end + else + respond_to do |format| + format.html { + settings + render :action => 'settings' + } + format.api { render_validation_errors(@course) } + end + end + end + + def new_join + @course = Course.find(params[:object_id]) + end + + # 课程搜索 + # add by nwb + def search + courses_all = Course.all_course + name = params[:name] + (redirect_to courses_path, :notice => l(:label_sumbit_empty);return) if name.blank? + @courses = courses_all.visible + if params[:name].present? + @courses_all = @courses.like(params[:name]) + else + @courses_all = @courses; + end + @course_count = @courses_all.count + @course_pages = Paginator.new @course_count, per_page_option, params['page'] + + # 课程的动态数 + @course_activity_count=Hash.new + @courses_all.each do |course| + @course_activity_count[course.id]=0 + end + + case params[:course_sort_type] + when '0' + @courses = @courses_all.order("created_at desc") + @s_type = 0 + @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) + + @course_activity_count=get_course_activity @courses,@course_activity_count + + when '1' + @courses = @courses_all.order("course_ac_para desc") + @s_type = 1 + @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) + + @course_activity_count=get_course_activity @courses,@course_activity_count + + when '2' + @courses = @courses_all.order("watchers_count desc") + @s_type = 2 + @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) + + @course_activity_count=get_course_activity @courses,@course_activity_count + + when '3' + @course_activity_count=get_course_activity @courses_all,@course_activity_count_array + @courses=handle_course @courses_all,@course_activity_count + @s_type = 3 + @courses = @courses[@course_pages.offset, @course_pages.per_page] + + else + @s_type = 0 + @courses = @courses_all.order("created_at desc") + @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) + + @course_activity_count=get_course_activity @courses,@course_activity_count + + end + + respond_to do |format| + format.html { + render :layout => 'course_base' + scope = Course + unless params[:closed] + scope = scope.active + end + } + format.atom { + courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all + render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}") + } + end + end + + def member + ## 有角色参数的才是课程,没有的就是项目 + @render_file = 'member_list' + @teachers= searchTeacherAndAssistant(@course) + @canShowCode = isCourseTeacher(User.current.id,@course) + case params[:role] + when '1' + @subPage_title = l :label_teacher_list + @members = searchTeacherAndAssistant(@course) + when '2' + @subPage_title = l :label_student_list + @members = searchStudent(@course) + else + @subPage_title = '' + @members = @course.member_principals.includes(:roles, :principal).all.sort + end + @members = paginateHelper @members + render :layout => 'base_courses' + end + + #判断指定用户是否为课程教师 + def isCourseTeacher(id) + result = false + if @teachers.find_by_user_id(id) != nil + result = true + end + result + end + + def handle_course courses, activities + course_activity_count_array=activities.values() + + course_array=[] + i=0; + courses.each do |course| + course_array[i]=course + i=i+1 + end + + courses=desc_sort_course_by_avtivity(course_activity_count_array, course_array) + + return courses + end + + def settings + @issue_custom_fields = IssueCustomField.sorted.all + @issue_category ||= IssueCategory.new + @member ||= @course.members.new + @trackers = Tracker.sorted.all + end + + def create + if User.current.user_extensions.identity + @course = Course.new + @course.extra='course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s + @course.safe_attributes = params[:course] + @course.tea_id = User.current.id + # added by bai + @course.term = params[:term] + @course.time = params[:time] + #@course.school_id = params[:occupation] + @course.school_id = User.current.user_extensions.school_id + @course.setup_time = params[:setup_time] + @course.endup_time = params[:endup_time] + @course.class_period = params[:class_period] + end + + @issue_custom_fields = IssueCustomField.sorted.all + @trackers = Tracker.sorted.all + + if User.current.user_extensions.identity == 0 + if @course.save + #unless User.current.admin? + r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first + m = Member.new(:user => User.current, :roles => [r]) + m.project_id = -1 + course = CourseInfos.new(:user_id => User.current.id, :course_id => @course.id) + #user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id) + if params[:course][:is_public] == '1' + course_status = CourseStatus.create(:course_id => @course.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :course_type => @course_tag) + end + @course.members << m + @course.course_infos << course + #end + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_create) + if params[:continue] + redirect_to new_course_path(attrs, :course => '0') + elsif params[:course_continue] + redirect_to new_course_path(:course => '1') + else + redirect_to settings_course_path(@course, :course_type => 1) + end + } + format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) } + end + else + #@course.destroy + respond_to do |format| + format.html { render :action => 'new', :layout => 'base' } #Added by young + format.api { render_validation_errors(@course) } + end + end + end + + end + + def course + @school_id = params[:school_id] + per_page_option = 10 + if @school_id == "0" or @school_id.nil? + @courses_all = Course.active.visible. + joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id"). + else + @courses_all = Course.active.visible. + joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id"). + joins(:course_extra). + where("#{Course.table_name}.school_id = ?", @school_id) + end + + @course_count = @courses_all.count + @course_pages = Paginator.new @course_count, per_page_option, params['page'] + + #gcm activity count + + @course_activity_count=Hash.new + #count initialize + @courses_all.each do |course| + @course_activity_count[course.id]=0 + end + + #@course_activity_count=get_course_activity @courses_all,@course_activity_count + #gcm end + + + case params[:course_sort_type] + when '0' + @courses = @courses_all.order("created_on desc") + @s_type = 0 + @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) + + #gcm + @course_activity_count=get_course_activity @courses,@course_activity_count + #gcmend + + when '1' + @courses = @courses_all.order("course_ac_para desc") + @s_type = 1 + @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) + + #gcm + @course_activity_count=get_course_activity @courses,@course_activity_count + #gcmend + + when '2' + @courses = @courses_all.order("watchers_count desc") + @s_type = 2 + @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) + + #gcm + @course_activity_count=get_course_activity @courses,@course_activity_count + #gcmend + + #gcm + when '3' + + #gcm + @course_activity_count=get_course_activity @courses_all,@course_activity_count + #gcmend + + @courses=handle_course @courses_all,@course_activity_count + @s_type = 3 + @courses = @courses[@course_pages.offset, @course_pages.per_page] + else + @s_type = 0 + @courses = @courses_all.order("created_on desc") + @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) + + #gcm + @course_activity_count=get_course_activity @courses,@course_activity_count + #gcmend + + end + + respond_to do |format| + format.html { + render :layout => 'base' + } + format.api { + # @offset, @limit = api_offset_and_limit + # @course_count = Course.visible.count + # @courses = Course.visible.offset(@offset).limit(@limit).order('lft').all + } + format.atom { + courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all + render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}") + } + end + end + + + def new + @course_type = params[:course_type] ||= params[:course] + @issue_custom_fields = IssueCustomField.sorted.all + @trackers = Tracker.sorted.all + + @course = Course.new + @course.safe_attributes = params[:course] + + render :layout => 'base' + end + + + def desc_sort_course_by_avtivity(activity_count, courses) + return courses if activity_count.size<2 + (activity_count.size-2).downto(0) do |i| + (0..i).each do |j| + if activity_count[j] 'base' + } + format.atom { + courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all + render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}") + } + end + end + + def homework + @offset, @limit = api_offset_and_limit({:limit => 10}) + @bids = @course.homeworks.order('deadline DESC') + @bids = @bids.like(params[:name]) if params[:name].present? + @bid_count = @bids.count + @bid_pages = Paginator.new @bid_count, @limit, params['page'] + + @offset ||= @bid_pages.reverse_offset + unless @offset == 0 + @bids = @bids.offset(@offset).limit(@limit).all.reverse + else + limit = @bid_count % @limit + if limit == 0 + limit = 10 + end + @bids = @bids.offset(@offset).limit(limit).all.reverse + end + render :layout => 'base_courses' + end + + # 新建作业 + def new_homework + @homework = Bid.new + @homework.proportion + @homework.safe_attributes = params[:bid] + if (User.current.logged? && User.current.member_of_course?(Course.find params[:id] )) + render :layout => 'base_courses' + else + render_403 + end + + end + + + + def toggleCourse + @course_prefs = Course.find_by_extra(@course.extra) + unless (@course_prefs.teacher == User.current || User.current.admin?) + render_403 + end + end + + def get_courses + @user = User.current + membership = @user.coursememberships.all + membership.sort! {|older, newer| newer.created_on <=> older.created_on } + @memberships = [] + membership.collect { |e| + @memberships.push(e) + } + @memberships_doing = [] + @memberships_done = [] + now_time = Time.now.year + @memberships.map { |e| + end_time = e.course.get_time.year + isDone = course_endTime_timeout?(e.course) + if isDone + @memberships_done.push e + else + @memberships_doing.push e + end + } + end + + def finishcourse + yesterday = Date.today.prev_day.to_time + + @course_prefs.endup_time = yesterday + @save_flag = @course_prefs.save + get_courses + + respond_to do |format| + format.js + end + end + + + def restartcourse + day = Time.parse("3000-01-01") + + @course_prefs.endup_time = day + @save_flag = @course_prefs.save + get_courses + + respond_to do |format| + format.js { + render action:'finishcourse' + } + end + end + + def show + # try to redirect to the requested menu item + if params[:jump] && redirect_to_course_menu_item(@course, params[:jump]) + return + end + + @users_by_role = @course.users_by_role + if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id))) + @user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id) + end + + + @key = User.current.rss_key + #新增内容 + @days = Setting.activity_days_default.to_i + + if params[:from] + begin; @date_to = params[:from].to_date + 1; rescue; end + end + + has = { + "show_course_files" => true, + "show_course_news" => true, + "show_course_messages" => true, + "show_bids" => true, + "show_course_journals_for_messages" => true + } + @date_to ||= Date.today + 1 + # + @date_from = (@date_to - @days) > @course.created_at.to_date ? (@date_to - @days) : @course.created_at.to_date + #@date_from = @date_to - @days-1.years + @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id])) + # 决定显示所用用户或单个用户活动 + @activity = Redmine::Activity::Fetcher.new(User.current, :course => @course, + :with_subprojects => false, + :author => @author) + @activity.scope_select {|t| has["show_#{t}"]} + # modify by nwb + # 添加私密性判断 + if User.current.member_of_course?(@course)|| User.current.admin? + events = @activity.events(@date_from, @date_to) + else + events = @activity.events(@date_from, @date_to, :is_public => 1) + end + + # 无新动态时,显示老动态 + if events.count == 0 + if User.current.member_of_course?(@course)|| User.current.admin? + events = @activity.events + else + events = @activity.events(:is_public => 1) + end + end + + @offset, @limit = api_offset_and_limit({:limit => 10}) + @events_count = events.count + @events_pages = Paginator.new @events_count, @limit, params['page'] + @offset ||= @events_pages.offset + events = events.slice(@offset,@limit) + + @events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)} + # documents + @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' + # + @teachers= searchTeacherAndAssistant(@course) + @canShowRealName = isCourseTeacher(User.current.id,@course) + + if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id))) + @user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id) + end + + respond_to do |format| + format.html{render :layout => 'base_courses'} + format.api + end + end + + #判断指定用户是否为课程教师 + def isCourseTeacher(id,course) + result = false + user = User.find(id) + if user.nil? && user.allowed_to?(:as_teacher,course)#@teachers && @teachers.count != 0 && @teachers.find_by_user_id(id) != nil + result = true + end + result + end + + def feedback + page = params[:page] + # Find the page of the requested reply + @jours = @course.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') + @limit = 10 + if params[:r] && page.nil? + offset = @jours.count(:conditions => ["#{JournalsForMessage.table_name}.id > ?", params[:r].to_i]) + page = 1 + offset / @limit + end + + @feedback_count = @jours.count + @feedback_pages = Paginator.new @feedback_count, @limit, page + @offset ||= @feedback_pages.offset + @jour = @jours[@offset, @limit] + @state = false + respond_to do |format| + format.html{render :layout => 'base_courses'} + format.api + end + end + + + + private + + def allow_join + if course_endTime_timeout? Course.find(params[:object_id]) + respond_to do |format| + format.js { + @state = 2 + render :partial => 'set_join', + :locals => {:user => User.current, + :course => Course.find(params[:object_id]), + :object_id => params[:object_id] + } + } + end + end + end + + #验证是否显示课程 + def can_show_course + @first_page = FirstPage.where("page_type = 'project'").first + if @first_page.show_course == 2 + render_404 + end + end + + + +end diff --git a/app/views/contestnotifications/edit.html.erb b/app/views/contestnotifications/edit.html.erb index 1606d97d6..27e38f999 100644 --- a/app/views/contestnotifications/edit.html.erb +++ b/app/views/contestnotifications/edit.html.erb @@ -1,4 +1,4 @@ -

<%=l(:label_news)%>

+

<%=l(:label_edit_contest_notice)%>

<%= labelled_form_for @contestnotification, :url => contest_contestnotification_path, diff --git a/app/views/contestnotifications/show.html.erb b/app/views/contestnotifications/show.html.erb index a44ee5909..47cdd3a86 100644 --- a/app/views/contestnotifications/show.html.erb +++ b/app/views/contestnotifications/show.html.erb @@ -1,4 +1,8 @@ - +
<%= link_to(l(:button_edit), edit_contest_contestnotification_path(@contest, @contestnotification), @@ -27,7 +31,7 @@
-
+
<%= textilizable(@contestnotification, :description) %> @@ -62,7 +66,17 @@

<%= submit_tag l(:button_add) %> - <%= submit_tag l(:button_cancel), :onclick => "cancel();" %> + + + + <%= submit_tag l(:button_cancel), + :name => nil, + :onclick => "cancel();", + :type => 'button', + :class => "enterprise", + :onmouseout => "this.style.backgroundPosition = 'left top'", + :onmouseover => "this.style.backgroundPosition = 'left -30px'" + %>

<% end %> @@ -97,7 +111,8 @@ <%= l(:label_comment_plural) %> - + + <% if notificationcomment.author==User.current|| User.current.admin? %> <%= link_to(l(:label_bid_respond_delete), contest_contestnotification_notificationcomment_path(@contest, @contestnotification,notificationcomment), diff --git a/app/views/softapplications/_list.html.erb b/app/views/softapplications/_list.html.erb index e31aedda7..91c49cda3 100644 --- a/app/views/softapplications/_list.html.erb +++ b/app/views/softapplications/_list.html.erb @@ -9,30 +9,13 @@
<%= softapplication.description.truncate(95, omission: '...') %>
<%contest = softapplication.contests.first%> - - - - - - - - - - - - - - - - - - - - +

<%=l(:label_attendingcontestwork_belongs_contest)%>:<%= contest ? link_to(contest.name.truncate(14, omission: '...'), show_attendingcontest_contest_path(contest), title: contest.name.to_s ) : '尚未加入竞赛'%>

-

<%=l(:label_attendingcontestwork_belongs_type)%>:<%= softapplication.app_type_name.truncate(14, omission: '...') %>

- <%strTitle = softapplication.android_min_version_available%> -

<%=l(:label_attendingcontestwork_adaptive_system)%>:<%= strTitle.truncate(10,omisiion:'...') %>

+ + +

<%=l(:label_attendingcontestwork_belongs_type)%>:<%= softapplication.app_type_name ? softapplication.app_type_name.truncate(14, omission: '...') : "" %>

+ <% strTitle = softapplication.android_min_version_available %> +

<%=l(:label_attendingcontestwork_adaptive_system)%>:<%= strTitle ? strTitle.truncate(10,omisiion:'...') : "" %>

<%=l(:label_attendingcontestwork_developers)%>:<%= softapplication.application_developers %> diff --git a/config/locales/zh.yml b/config/locales/zh.yml index b3bdc53f7..2e6fe6ddb 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -705,6 +705,7 @@ zh: label_report_plural: 报表 label_news: 新闻 label_news_new: 添加新闻 + label_edit_contest_notice: 编辑竞赛通知 bale_news_notice: 添加通知 #huang bale_edit_notice: 修改通知 label_news_notice: 发布课程通知 @@ -2045,6 +2046,7 @@ zh: label_contest_settings: 配置竞赛 label_contest_delete: 删除竞赛 label_noawards_current: 暂未评奖 + label_softapplication: 应用软件 label_attending_contest: 参加竞赛