diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index ec06644bf..312af97b8 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -163,6 +163,100 @@ class CoursesController < ApplicationController 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"). + where("#{Course.table_name}.course_type = ? ", Course::CourseType_course) + 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}.course_type = ? AND #{Course.table_name}.school_id = ?", Course::CourseType_course, @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] @@ -327,7 +421,7 @@ class CoursesController < ApplicationController date_from = date_to - days-1.years #file_count - Attachment.where(container_id: @course_ids, container_type: Project).where("created_on>?", date_from).each do |attachment| + Attachment.where(container_id: @course_ids, container_type: Course).where("created_on>?", date_from).each do |attachment| activities[attachment.container_id]+=1 end @@ -338,7 +432,7 @@ class CoursesController < ApplicationController end #feedbackc_count - JournalsForMessage.where(jour_id: @course_ids, jour_type: Project).each do |jourformess| + JournalsForMessage.where(jour_id: @course_ids, jour_type: Course).each do |jourformess| activities[jourformess.jour_id]+=1 end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 3eed35699..d3c852d10 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -205,8 +205,9 @@ module CoursesHelper str end - def get_course_term project - str = ( project.try(:course_extra).try(:time).to_s << '.' << project.try(:course_extra).try(:term).to_s ) + # added by nwb + def get_course_term course + str = ( course.try(:time).to_s << '.' << course.try(:term).to_s ) str[0..-4] end diff --git a/app/models/course.rb b/app/models/course.rb index c853e15b1..b63b56c49 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -28,7 +28,7 @@ class Course < ActiveRecord::Base has_many :course_journals_for_messages, :class_name => 'CourseJournalsForMessage', :as => :jour, :dependent => :destroy acts_as_taggable - #acts_as_nested_set :order => 'name', :dependent => :destroy + acts_as_nested_set :order => 'name', :dependent => :destroy acts_as_attachable :view_permission => :view_files, :delete_permission => :manage_files @@ -73,6 +73,11 @@ class Course < ActiveRecord::Base user.allowed_to?(:view_course, self) end + # 课程的短描述信息 + def short_description(length = 255) + description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description + end + def extra_frozen? errors[:extra].blank? && !(new_record? || extra.blank?) end diff --git a/app/models/course_infos.rb b/app/models/course_infos.rb index d841c2eb7..6478b383a 100644 --- a/app/models/course_infos.rb +++ b/app/models/course_infos.rb @@ -1,3 +1,5 @@ class CourseInfos < ActiveRecord::Base attr_accessible :user_id, :course_id + belongs_to :user + belongs_to :course end diff --git a/app/views/courses/_course.html.erb b/app/views/courses/_course.html.erb index 3bf42bf2d..80cd7df9d 100644 --- a/app/views/courses/_course.html.erb +++ b/app/views/courses/_course.html.erb @@ -1,4 +1,4 @@ -
<% files_count = @course.attachments.count %> - <% @course.versions.each do |version| %> - <% files_count += version.attachments.count %> - <% end %> <%= content_tag('span', link_to(files_count, course_files_path(@course)), :class => "info") %> <%= content_tag('span', l(:label_x_data,:count => files_count)) %>
@@ -59,12 +56,12 @@- <%= l(:label_project_cousre_studentun) %><%= link_to"#{l(:label_course_join_student)}",{:controller=>'projects',:action=>'course', :course => 1}, :class => 'icon icon-add' %> + <%= l(:label_project_cousre_studentun) %><%= link_to"#{l(:label_course_join_student)}",{:controller=>'courses',:action=>'index'}, :class => 'icon icon-add' %>
<% end %> <% else %> diff --git a/db/migrate/20140606028512_add_course_roles.rb b/db/migrate/20140606028512_add_course_roles.rb index 68da9b194..68991b52b 100644 --- a/db/migrate/20140606028512_add_course_roles.rb +++ b/db/migrate/20140606028512_add_course_roles.rb @@ -6,6 +6,7 @@ class AddCourseRoles < ActiveRecord::Migration if role.name == 'Non member' role.permissions.append(:view_course ) role.permissions.append(:search_course ) + role.permissions.append(:add_course ) elsif role.name == 'Anonymous' role.permissions.append(:view_course ) role.permissions.append(:search_course )