From 7d3d406c006e91f9296277550951b19974493838 Mon Sep 17 00:00:00 2001 From: nwb Date: Tue, 3 Jun 2014 11:16:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=83=A8=E5=88=86=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E6=89=80=E9=9C=80=E7=9A=84=E8=A7=A3=E6=9E=90=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 94 ++++++++++++++++++--------- app/helpers/application_helper.rb | 4 +- app/models/course.rb | 8 +++ app/views/courses/index.html.erb | 12 ++-- 4 files changed, 82 insertions(+), 36 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 3060d1f07..3ebd3369c 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f89023b7e..da674bb56 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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'} diff --git a/app/models/course.rb b/app/models/course.rb index 0bc93c811..0c5abd5c2 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -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 diff --git a/app/views/courses/index.html.erb b/app/views/courses/index.html.erb index a74668dc4..ea32d3863 100644 --- a/app/views/courses/index.html.erb +++ b/app/views/courses/index.html.erb @@ -29,21 +29,23 @@ <% end %> -<%= sort_course(@s_type, @course_type, @school_id)%> +<%= sort_course(@s_type, @school_id)%> -
- <%= render_project_hierarchy(@projects)%> +
+ <%if @courses%> + <%= render_course_hierarchy(@courses)%> + <%end%>
<% if User.current.logged? %>

- <%= l(:label_my_course) %> + <%= l(:label_my_course) %>

<% end %>