1.Non member角色添加add_couese权限

2.course_helper优化排序等相关函数
3.课程index界面修改
This commit is contained in:
nwb 2014-06-10 17:03:02 +08:00
parent f741b0581c
commit a793b8923d
8 changed files with 115 additions and 14 deletions

View File

@ -163,6 +163,100 @@ class CoursesController < ApplicationController
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").
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 def new
@course_type = params[:course_type] ||= params[:course] @course_type = params[:course_type] ||= params[:course]
@ -327,7 +421,7 @@ class CoursesController < ApplicationController
date_from = date_to - days-1.years date_from = date_to - days-1.years
#file_count #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 activities[attachment.container_id]+=1
end end
@ -338,7 +432,7 @@ class CoursesController < ApplicationController
end end
#feedbackc_count #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 activities[jourformess.jour_id]+=1
end end

View File

@ -205,8 +205,9 @@ module CoursesHelper
str str
end end
def get_course_term project # added by nwb
str = ( project.try(:course_extra).try(:time).to_s << '.' << project.try(:course_extra).try(:term).to_s ) def get_course_term course
str = ( course.try(:time).to_s << '.' << course.try(:term).to_s )
str[0..-4] str[0..-4]
end end

View File

@ -28,7 +28,7 @@ class Course < ActiveRecord::Base
has_many :course_journals_for_messages, :class_name => 'CourseJournalsForMessage', :as => :jour, :dependent => :destroy has_many :course_journals_for_messages, :class_name => 'CourseJournalsForMessage', :as => :jour, :dependent => :destroy
acts_as_taggable 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, acts_as_attachable :view_permission => :view_files,
:delete_permission => :manage_files :delete_permission => :manage_files
@ -73,6 +73,11 @@ class Course < ActiveRecord::Base
user.allowed_to?(:view_course, self) user.allowed_to?(:view_course, self)
end end
# 课程的短描述信息
def short_description(length = 255)
description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
end
def extra_frozen? def extra_frozen?
errors[:extra].blank? && !(new_record? || extra.blank?) errors[:extra].blank? && !(new_record? || extra.blank?)
end end

View File

@ -1,3 +1,5 @@
class CourseInfos < ActiveRecord::Base class CourseInfos < ActiveRecord::Base
attr_accessible :user_id, :course_id attr_accessible :user_id, :course_id
belongs_to :user
belongs_to :course
end end

View File

@ -1,4 +1,4 @@
<div class="course-block"> <div class="project-block">
<div class="img-tag-2"> <div class="img-tag-2">
<% if get_avatar?(course)%> <% if get_avatar?(course)%>
<%= image_tag(url_to_avatar(course), :class => "avatar2") %> <%= image_tag(url_to_avatar(course), :class => "avatar2") %>
@ -18,7 +18,7 @@
<%if @admin&&@admin.first&&@admin.first.user&&@admin.first.user.user_extensions%> <%if @admin&&@admin.first&&@admin.first.user&&@admin.first.user.user_extensions%>
<!-- <%= @admin.first.user.user_extensions.occupation %> --> <!-- <%= @admin.first.user.user_extensions.occupation %> -->
<%# unless @course.course_extra.school.nil? %> <%# unless @course.course_extra.school.nil? %>
<%= @course.course_extra.teacher.user_extensions.school.try(:name) %> <%= @course.teacher.user_extensions.school.try(:name) %>
<%# end %> <%# end %>
<% end %> <% end %>
</p> </p>
@ -38,9 +38,6 @@
</p> </p>
<p class="stats"> <p class="stats">
<% files_count = @course.attachments.count %> <% 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', link_to(files_count, course_files_path(@course)), :class => "info") %>
<%= content_tag('span', l(:label_x_data,:count => files_count)) %> <%= content_tag('span', l(:label_x_data,:count => files_count)) %>
</p> </p>
@ -59,12 +56,12 @@
<div class="buttons_for_course" style="margin-top:30px;margin-left:144px"> <div class="buttons_for_course" style="margin-top:30px;margin-left:144px">
<span class="info"></span> <span class="info"></span>
<% if(course_endTime_timeout? @project) %> <% if(course_endTime_timeout? @course) %>
<span class="font_lighter"> <span class="font_lighter">
课程学期已结束 课程学期已结束
</span> </span>
<% else %> <% else %>
<%= join_in_course_for_list(@project, User.current,['regular'])%> <%= join_in_course_for_list(@course, User.current,['regular'])%>
<% end -%> <% end -%>
</div> </div>
</div> </div>

View File

@ -11,7 +11,8 @@
<td rowspan="2"> <td rowspan="2">
<% if User.current.logged?%> <% if User.current.logged?%>
<% if User.current.user_extensions.identity == 0 %> <% if User.current.user_extensions.identity == 0 %>
<%= link_to(l(:label_course_new), {:controller => 'courses', :action => 'new', :course => 1}, :class => 'icon icon-add') if User.current.allowed_to?(:add_course, nil, :global => true) %></td> <%= link_to(l(:label_course_new), {:controller => 'courses', :action => 'new'},
:class => 'icon icon-add') if User.current.allowed_to?(:add_course,nil, :global => true) %></td>
<% end %> <% end %>
<% end %> <% end %>
</td> </td>

View File

@ -7,7 +7,7 @@
<% else %> <% else %>
<p class="font_description"> <p class="font_description">
<%= 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' %>
</p> </p>
<% end %> <% end %>
<% else %> <% else %>

View File

@ -6,6 +6,7 @@ class AddCourseRoles < ActiveRecord::Migration
if role.name == 'Non member' if role.name == 'Non member'
role.permissions.append(:view_course ) role.permissions.append(:view_course )
role.permissions.append(:search_course ) role.permissions.append(:search_course )
role.permissions.append(:add_course )
elsif role.name == 'Anonymous' elsif role.name == 'Anonymous'
role.permissions.append(:view_course ) role.permissions.append(:view_course )
role.permissions.append(:search_course ) role.permissions.append(:search_course )