新增部分课程所需的解析函数

This commit is contained in:
nwb 2014-06-03 11:16:06 +08:00
parent 9f948c971f
commit 7d3d406c00
4 changed files with 82 additions and 36 deletions

View File

@ -52,37 +52,19 @@ class CoursesController < ApplicationController
end
end
private
def allow_join
if course_endTime_timeout? Project.find(params[:object_id])
respond_to do |format|
format.js{
@state = 2
render :partial => 'set_join',
:locals => {:user => User.current,
:course => Project.find(params[:object_id]),
:object_id => params[:object_id]
}
}
end
end
end
def index
@course_type = params[:course_type]
@school_id = params[:school_id]
per_page_option = 10
if @school_id == "0" or @school_id.nil?
@courses_all = Project.active.visible.
joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.course_id").
where("#{Project.table_name}.course_type = ? ", Project::ProjectType_course)
@courses_all = Course.active.visible.
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id")
else
@courses_all = Project.active.visible.
joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.course_id").
@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("#{Project.table_name}.course_type = ? AND #{Course.table_name}.school_id = ?", Project::ProjectType_course, @school_id)
where("#{Course.table_name}.course_type = ? AND #{Course.table_name}.school_id = ?", Course::CourseType_course, @school_id)
end
@course_count = @courses_all.count
@ -153,18 +135,72 @@ class CoursesController < ApplicationController
format.html {
render :layout => 'base'
}
format.api {
# @offset, @limit = api_offset_and_limit
# @course_count = Project.visible.count
# @courses = Project.visible.offset(@offset).limit(@limit).order('lft').all
}
format.atom {
courses = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
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 get_course_activity courses,activities
@course_ids=activities.keys()
days = Setting.activity_days_default.to_i
date_to ||= Date.today + 1
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|
activities[attachment.container_id]+=1
end
#message_count
Board.where(course_id: @course_ids).each do |board|
# activities[board.course_id]+=1
activities[board.course_id]+=board.messages.where("updated_on>?",date_from).count
end
#time_entry_count
TimeEntry.where(course_id: @course_ids).where("updated_on>?",date_from).each do |timeentry|
activities[timeentry.course_id]+=1
end
#feedbackc_count
JournalsForMessage.where(jour_id: @course_ids, jour_type: Project).each do |jourformess|
activities[jourformess.jour_id]+=1
end
#activities!=0
i=0;
courses.each do |course|
id=course.id
if activities[id]==0
activities[id]=1
end
end
return activities
end
private
def allow_join
if course_endTime_timeout? Project.find(params[:object_id])
respond_to do |format|
format.js{
@state = 2
render :partial => 'set_join',
:locals => {:user => User.current,
:course => Project.find(params[:object_id]),
:object_id => params[:object_id]
}
}
end
end
end
def index1

View File

@ -1685,9 +1685,9 @@ module ApplicationHelper
main_project_link = link_to l(:label_project_deposit), {:controller => 'welcome', :action => 'index', :host => Setting.project_domain}
main_contest_link = link_to l(:label_contest_innovate), {:controller => 'welcome', :action => 'index', :host => Setting.contest_domain}
course_all_course_link = link_to l(:label_course_all), {:controller => 'courses', :action => 'index', :host => Setting.course_domain}
course_all_course_link = link_to l(:label_course_all), {:controller => 'courses', :action => 'index'}
course_teacher_all_link = link_to l(:label_teacher_all), {:controller => 'users', :action => 'index', :role => 'teacher', :host => Setting.course_domain}
courses_link = link_to l(:label_course_practice), {:controller => 'courses', :action => 'index',:host => Setting.course_domain}
courses_link = link_to l(:label_course_practice), {:controller => 'courses', :action => 'index'}
projects_link = link_to l(:label_project_deposit), {:controller => 'projects', :action => 'index', :project_type => 0, :host => Setting.project_domain}
users_link = link_to l(:label_software_user), {:controller => 'users', :action => 'index', :host => Setting.user_domain}
contest_link = link_to l(:label_contest_innovate), {:controller => 'contests', :action => 'index'}

View File

@ -39,6 +39,14 @@ class Course < ActiveRecord::Base
where(Course.allowed_to_condition(user, permission, *args))
}
def visible?(user=User.current)
user.allowed_to?(:view_course, self)
end
def self.visible_condition(user, options={})
allowed_to_condition(user, :view_course, options)
end
#自定义验证
def validate

View File

@ -29,21 +29,23 @@
</table>
<% end %>
</div>
<%= sort_course(@s_type, @course_type, @school_id)%>
<%= sort_course(@s_type, @school_id)%>
<div id="projects-index">
<%= render_project_hierarchy(@projects)%>
<div id="courses-index">
<%if @courses%>
<%= render_course_hierarchy(@courses)%>
<%end%>
</div>
<div class="pagination">
<ul>
<%= pagination_links_full @project_pages, @project_count %>
<%= pagination_links_full @course_pages, @course_count %>
</ul>
</div>
<% if User.current.logged? %>
<p style="text-align:right;">
<span class="my-project"><%= l(:label_my_course) %></span>
<span class="my-course"><%= l(:label_my_course) %></span>
</p>
<% end %>