parent
329be27567
commit
fb398904b6
|
@ -759,6 +759,18 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def paginateHelper_for_members obj, pre_size=10
|
||||||
|
@obj_count = StudentsForCourse.find_by_sql("select count(id) as mem_count from students_for_courses where course_id = #{@course.id}")[0][:mem_count].to_s.to_i
|
||||||
|
@obj_pages = Paginator.new @obj_count, pre_size, params['page']
|
||||||
|
if obj.kind_of? ActiveRecord::Base or obj.kind_of? ActiveRecord::Relation
|
||||||
|
obj.limit(@obj_pages.per_page).offset(0)
|
||||||
|
elsif obj.kind_of? Array
|
||||||
|
obj[0, @obj_pages.per_page]
|
||||||
|
else
|
||||||
|
logger.error "[ApplicationController] Error : application_controller#paginateHelper ===> unknow category: #{obj.class}"
|
||||||
|
raise RuntimeError, 'unknow type, Please input you type into this helper.'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
#查找首页相关信息
|
#查找首页相关信息
|
||||||
def find_first_page
|
def find_first_page
|
||||||
|
|
|
@ -23,7 +23,7 @@ class CoursesController < ApplicationController
|
||||||
|
|
||||||
before_filter :require_login, :only => [:join, :unjoin]
|
before_filter :require_login, :only => [:join, :unjoin]
|
||||||
#before_filter :allow_join, :only => [:join]
|
#before_filter :allow_join, :only => [:join]
|
||||||
@@result = nil
|
|
||||||
def join
|
def join
|
||||||
if User.current.logged?
|
if User.current.logged?
|
||||||
course = Course.find_by_id params[:object_id]
|
course = Course.find_by_id params[:object_id]
|
||||||
|
@ -213,10 +213,11 @@ class CoursesController < ApplicationController
|
||||||
q = "#{params[:name].strip}"
|
q = "#{params[:name].strip}"
|
||||||
#(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
|
#(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
|
||||||
if params[:incourse]
|
if params[:incourse]
|
||||||
@results = searchmember_by_name(student_homework_score, q)
|
@results = searchmember_by_name(student_homework_score(0,0,0), q)
|
||||||
|
|
||||||
elsif params[:ingroup]
|
elsif params[:ingroup]
|
||||||
@group = CourseGroup.find(params[:search_group_id])
|
@group = CourseGroup.find(params[:search_group_id])
|
||||||
@results =searchgroupmember_by_name(student_homework_score, @group, q)
|
@results = searchmember_by_name(student_homework_score(@group.id,0,0), q)
|
||||||
end
|
end
|
||||||
@is_remote = true
|
@is_remote = true
|
||||||
@result_count = @results.count
|
@result_count = @results.count
|
||||||
|
@ -285,9 +286,9 @@ class CoursesController < ApplicationController
|
||||||
member.course_group_id = group.id
|
member.course_group_id = group.id
|
||||||
member.save
|
member.save
|
||||||
@group = group
|
@group = group
|
||||||
@members = student_homework_score
|
|
||||||
@course_groups = @course.course_groups
|
@course_groups = @course.course_groups
|
||||||
@membercount = @members.count
|
|
||||||
search_group_members group
|
search_group_members group
|
||||||
end
|
end
|
||||||
def unjoin_group
|
def unjoin_group
|
||||||
|
@ -298,8 +299,7 @@ class CoursesController < ApplicationController
|
||||||
member.save
|
member.save
|
||||||
@group = group
|
@group = group
|
||||||
@course_groups = @course.course_groups
|
@course_groups = @course.course_groups
|
||||||
@members = student_homework_score
|
|
||||||
@membercount = @members.count
|
|
||||||
search_group_members group
|
search_group_members group
|
||||||
end
|
end
|
||||||
def searchgroupmembers
|
def searchgroupmembers
|
||||||
|
@ -309,15 +309,19 @@ class CoursesController < ApplicationController
|
||||||
@is_remote = true
|
@is_remote = true
|
||||||
if params[:group_id] && params[:group_id] != "0"
|
if params[:group_id] && params[:group_id] != "0"
|
||||||
@group = CourseGroup.find(params[:group_id])
|
@group = CourseGroup.find(params[:group_id])
|
||||||
@results = student_homework_score.find_all {|mem| mem.course_group_id == @group.id}
|
|
||||||
|
@results = student_homework_score(@group.id,0, 0)
|
||||||
|
@results = paginateHelper @results, 10
|
||||||
|
|
||||||
|
|
||||||
else
|
else
|
||||||
@results = student_homework_score
|
page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1)
|
||||||
|
@results = student_homework_score(0,page_from, 10)
|
||||||
|
@results = paginateHelper_for_members @results, 10
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@members = searchStudent(@course)
|
|
||||||
@membercount = @members.count
|
|
||||||
@results = paginateHelper @results
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -325,31 +329,36 @@ class CoursesController < ApplicationController
|
||||||
## 有角色参数的才是课程,没有的就是项目
|
## 有角色参数的才是课程,没有的就是项目
|
||||||
if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course)))
|
if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course)))
|
||||||
@render_file = 'member_list'
|
@render_file = 'member_list'
|
||||||
@teachers= searchTeacherAndAssistant(@course)
|
|
||||||
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
|
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
|
||||||
@role = params[:role]
|
@role = params[:role].nil? ? '2':params[:role]
|
||||||
@is_remote = false
|
@is_remote = true
|
||||||
@course_groups = @course.course_groups if @course.course_groups
|
@course_groups = @course.course_groups if @course.course_groups
|
||||||
@show_serch = params[:role] == '2'
|
@show_serch = params[:role] == '2'
|
||||||
case params[:role]
|
case @role
|
||||||
when '1'
|
when '1'
|
||||||
@subPage_title = l :label_teacher_list
|
@subPage_title = l :label_teacher_list
|
||||||
@members = @teachers
|
@members = searchTeacherAndAssistant(@course)
|
||||||
|
@members = paginateHelper @members, 10
|
||||||
when '2'
|
when '2'
|
||||||
@subPage_title = l :label_student_list
|
@subPage_title = l :label_student_list
|
||||||
@members = student_homework_score
|
page = params[:page].nil? ? 0 : (params['page'].to_i - 1)
|
||||||
|
@members = student_homework_score(0,page, 10)
|
||||||
|
|
||||||
# @member_scores = @@member_scores
|
@members = paginateHelper_for_members @members, 10
|
||||||
# @members = searchStudent_sort(@course, 'desc', @@member_scores)
|
|
||||||
@membercount = @members.count
|
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
if params[:page]
|
||||||
|
format.js
|
||||||
else
|
else
|
||||||
@subPage_title = ''
|
format.html {render :layout => 'base_courses'}
|
||||||
@members = @course.member_principals.includes(:roles, :principal).all.sort
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@members = paginateHelper @members
|
# render :layout => 'base_courses'
|
||||||
render :layout => 'base_courses'
|
|
||||||
else
|
else
|
||||||
render_403
|
render_403
|
||||||
end
|
end
|
||||||
|
@ -378,19 +387,11 @@ class CoursesController < ApplicationController
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {render :layout => 'course_base'}
|
format.html {render :layout => 'course_base'}
|
||||||
format.js
|
format.js
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#判断指定用户是否为课程教师
|
|
||||||
def isCourseTeacher(id)
|
|
||||||
result = false
|
|
||||||
if @teachers.find_by_user_id(id) != nil
|
|
||||||
result = true
|
|
||||||
end
|
|
||||||
result
|
|
||||||
end
|
|
||||||
|
|
||||||
def handle_course courses, activities
|
def handle_course courses, activities
|
||||||
course_activity_count_array=activities.values()
|
course_activity_count_array=activities.values()
|
||||||
|
|
||||||
|
@ -881,11 +882,13 @@ class CoursesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def student_homework_score
|
def student_homework_score(groupid,start_from, nums)
|
||||||
#teachers = find_course_teachers(@course)
|
#teachers = find_course_teachers(@course)
|
||||||
|
start_from = start_from * nums
|
||||||
sql = ActiveRecord::Base.connection()
|
sql = ActiveRecord::Base.connection()
|
||||||
|
|
||||||
|
homework_scores = Member.find_by_sql("call member_score(#{@course.id},#{groupid},#{start_from},#{nums})")
|
||||||
|
|
||||||
homework_scores = Member.find_by_sql("call member_score(#{@course.id})")
|
|
||||||
sql.close()
|
sql.close()
|
||||||
homework_scores
|
homework_scores
|
||||||
end
|
end
|
||||||
|
@ -901,10 +904,10 @@ class CoursesController < ApplicationController
|
||||||
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
|
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
|
||||||
@is_remote = true
|
@is_remote = true
|
||||||
|
|
||||||
@members = searchStudent(@course)
|
|
||||||
@membercount = @members.count
|
page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1)
|
||||||
@results = student_homework_score.find_all {|mem| mem.course_group_id == group.id}
|
@results = student_homework_score(group.id,0,0)
|
||||||
@@result = @results
|
@results = paginateHelper @results, 10
|
||||||
@results = paginateHelper @results
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
$("#member_content").html("<%= escape_javascript( render :partial => @render_file, :locals => {:members => @members})%>");
|
|
@ -0,0 +1,100 @@
|
||||||
|
class ProMemberScore < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
sql_delete = ("DROP PROCEDURE IF EXISTS `member_score`;")
|
||||||
|
sql = ("
|
||||||
|
CREATE PROCEDURE `member_score`(IN courseid INT, IN groupid INT,IN start_from INT, IN nums INT)
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
CREATE TEMPORARY TABLE IF NOT EXISTS course_teachers (
|
||||||
|
id INT
|
||||||
|
|
||||||
|
);
|
||||||
|
TRUNCATE TABLE course_teachers;
|
||||||
|
|
||||||
|
CREATE TEMPORARY TABLE IF NOT EXISTS mems (
|
||||||
|
id INT ,
|
||||||
|
user_id INT,
|
||||||
|
course_id INT,
|
||||||
|
created_on DATETIME,
|
||||||
|
course_group_id INT,
|
||||||
|
score FLOAT DEFAULT 0
|
||||||
|
);
|
||||||
|
TRUNCATE TABLE mems;
|
||||||
|
|
||||||
|
CREATE TEMPORARY TABLE IF NOT EXISTS mem_home (
|
||||||
|
id INT,
|
||||||
|
user_id INT,
|
||||||
|
course_id INT,
|
||||||
|
created_on DATETIME,
|
||||||
|
course_group_id INT,
|
||||||
|
home_id INT,
|
||||||
|
score FLOAT DEFAULT 0
|
||||||
|
);
|
||||||
|
TRUNCATE TABLE mem_home;
|
||||||
|
|
||||||
|
CREATE TEMPORARY TABLE IF NOT EXISTS t_scores (
|
||||||
|
|
||||||
|
home_id INT,
|
||||||
|
score FLOAT
|
||||||
|
);
|
||||||
|
TRUNCATE TABLE t_scores;
|
||||||
|
|
||||||
|
CREATE TEMPORARY TABLE IF NOT EXISTS s_scores (
|
||||||
|
|
||||||
|
home_id INT,
|
||||||
|
score FLOAT
|
||||||
|
);
|
||||||
|
TRUNCATE TABLE s_scores;
|
||||||
|
|
||||||
|
CREATE TEMPORARY TABLE IF NOT EXISTS scores (
|
||||||
|
|
||||||
|
user_id INT,
|
||||||
|
score FLOAT
|
||||||
|
);
|
||||||
|
TRUNCATE TABLE scores;
|
||||||
|
|
||||||
|
INSERT INTO course_teachers (SELECT members.user_id FROM members WHERE members.user_id NOT IN (SELECT student_id FROM students_for_courses WHERE course_id = courseid));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
INSERT INTO mems (id, user_id, course_id, created_on, course_group_id)
|
||||||
|
(SELECT members.id, members.user_id, members.course_id, members.created_on, members.course_group_id
|
||||||
|
FROM members WHERE course_id = courseid AND members.user_id NOT IN (SELECT id FROM course_teachers));
|
||||||
|
|
||||||
|
INSERT INTO mem_home (id, user_id, course_id, created_on, course_group_id,home_id)
|
||||||
|
(SELECT members.id, members.user_id, members.course_id, members.created_on, members.course_group_id, homework_attaches.id
|
||||||
|
FROM members, homework_attaches WHERE course_id = courseid
|
||||||
|
AND members.user_id = homework_attaches.user_id AND members.user_id NOT IN (SELECT id FROM course_teachers)
|
||||||
|
AND homework_attaches.bid_id IN (SELECT bid_id FROM homework_for_courses WHERE course_id = courseid ));
|
||||||
|
|
||||||
|
INSERT INTO t_scores (home_id, score) (SELECT rateable_id,AVG(seems_rateable_rates.stars)
|
||||||
|
FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id IN (SELECT mem_home.home_id FROM mem_home)
|
||||||
|
AND rater_id IN (SELECT id FROM course_teachers)
|
||||||
|
GROUP BY rateable_id);
|
||||||
|
|
||||||
|
INSERT INTO s_scores (home_id, score) (SELECT rateable_id,AVG(seems_rateable_rates.stars)
|
||||||
|
FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id IN (SELECT mem_home.home_id FROM mem_home)
|
||||||
|
AND rater_id NOT IN (SELECT id FROM course_teachers)
|
||||||
|
GROUP BY rateable_id) ;
|
||||||
|
|
||||||
|
UPDATE mem_home, t_scores SET mem_home.score = t_scores.score WHERE mem_home.home_id = t_scores.home_id ;
|
||||||
|
|
||||||
|
UPDATE mem_home, s_scores SET mem_home.score = s_scores.score WHERE mem_home.home_id = s_scores.home_id AND mem_home.score = 0;
|
||||||
|
|
||||||
|
INSERT INTO scores (user_id, score) (SELECT user_id, SUM(score) FROM mem_home GROUP BY user_id);
|
||||||
|
UPDATE mems, scores SET mems.score = scores.score WHERE mems.user_id = scores.user_id;
|
||||||
|
IF nums <> 0 THEN
|
||||||
|
SELECT * FROM mems ORDER BY score DESC LIMIT start_from, nums;
|
||||||
|
ELSE
|
||||||
|
SELECT * FROM mems WHERE course_group_id = groupid ORDER BY score DESC;
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
|
||||||
|
")
|
||||||
|
execute(sql_delete)
|
||||||
|
execute(sql)
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20141226074532) do
|
ActiveRecord::Schema.define(:version => 20141229081716) do
|
||||||
|
|
||||||
create_table "activities", :force => true do |t|
|
create_table "activities", :force => true do |t|
|
||||||
t.integer "act_id", :null => false
|
t.integer "act_id", :null => false
|
||||||
|
|
Loading…
Reference in New Issue