dev_xiangzheng
ouyangxuhua 10 years ago
commit 6924a3e7bb

@ -354,7 +354,7 @@ class AdminController < ApplicationController
@schools = School.where('1=1') @schools = School.where('1=1')
end end
@school_count = @schools.count @school_count = @schools.count
@school_pages = Paginator.new @school_count, per_page_option, params['page'] || 1 @school_pages = Paginator.new @school_count, 100, params['page'] || 1
@schools = paginateHelper @schools,100 @schools = paginateHelper @schools,100
respond_to do |format| respond_to do |format|
format.html format.html

@ -31,17 +31,17 @@ class CoursesController < ApplicationController
def join def join
if User.current.logged? if User.current.logged?
if params[:role] == 10 # if params[:role] == 10
cs = CoursesService.new cs = CoursesService.new
@user = User.current @user = User.current
join = cs.join_course params,user join = cs.join_course params,@user
@state = join[:state] @state = join[:state]
@course = join[:course] @course = join[:course]
else # else
@course = Course.find_by_id params[:object_id] # @course = Course.find_by_id params[:object_id]
CourseMessage.create(:user_id => @course.tea_id, :course_id => @course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest') # CourseMessage.create(:user_id => @course.tea_id, :course_id => @course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest')
@state = 6 # @state = 6
end # end
else else
@state = 5 #未登录 @state = 5 #未登录
end end

@ -15,11 +15,11 @@ class CoursesService
page_no = params[:page] || 1 page_no = params[:page] || 1
if @school_id == "0" || @school_id.nil? if @school_id == "0" || @school_id.nil?
@courses_all = Course.active.visible. @courses_all = Course.active.visible.
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id") joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id")
else else
@courses_all = Course.active.visible. @courses_all = Course.active.visible.
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id"). joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id").
where("#{Course.table_name}.school_id = ?", @school_id) where("#{Course.table_name}.school_id = ?", @school_id)
end end
@course_count = @courses_all.count @course_count = @courses_all.count
@course_pages = Redmine::Pagination::Paginator.new @course_count, per_page_option,page_no @course_pages = Redmine::Pagination::Paginator.new @course_count, per_page_option,page_no
@ -300,6 +300,7 @@ class CoursesService
#@state == 4 您加入的课程不存在 #@state == 4 您加入的课程不存在
#@state == 5 您还未登录 #@state == 5 您还未登录
#@state == 6 申请成功,请等待审核完毕 #@state == 6 申请成功,请等待审核完毕
#@state == 7 您已经发送过申请了,请耐心等待
#@state 其他 未知错误,请稍后再试 #@state 其他 未知错误,请稍后再试
def join_course params,current_user def join_course params,current_user
course = Course.find_by_id params[:object_id] course = Course.find_by_id params[:object_id]
@ -308,15 +309,38 @@ class CoursesService
if course_endTime_timeout? course if course_endTime_timeout? course
@state = 2 @state = 2
else else
if current_user.member_of_course?(course) if current_user.member_of_course?(course) #如果已经是成员
@state = 3 if params[:course_password] == course.password
#如果加入角色为学生
if params[:role] == "10"
@state = 3
elsif current_user.allowed_to?(:as_teacher,course)
@state = 3
else
#如果加入角色为教师或者教辅
CourseMessage.create(:user_id => course.tea_id, :course_id => course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest',:status=>0)
@state = 6
end
else
@state = 1
end
else else
if params[:course_password] == course.password if params[:course_password] == course.password
members = [] if params[:role] == "10"
members << Member.new(:role_ids => [10], :user_id => current_user.id) members = []
course.members << members members << Member.new(:role_ids => [10], :user_id => current_user.id)
StudentsForCourse.create(:student_id => current_user.id, :course_id => params[:object_id]) course.members << members
@state = 0 StudentsForCourse.create(:student_id => current_user.id, :course_id => params[:object_id])
@state = 0
else
#如果已经发送过消息了,那么就要给个提示
if CourseMessage.where("course_message_type = 'JoinCourseRequest' and user_id = #{course.tea_id} and content = #{params[:role]} and course_message_id = #{User.current.id} and course_id = #{course.id} and status = 0").count != 0
@state = 7
else
CourseMessage.create(:user_id => course.tea_id, :course_id => course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest',:status=>0)
@state = 6
end
end
else else
@state = 1 @state = 1
end end
@ -336,11 +360,11 @@ class CoursesService
if course.is_public != 0 || current_user.member_of_course?(course) if course.is_public != 0 || current_user.member_of_course?(course)
bids = course.homework_commons.page(params[:page] || 1).per(20).order('created_at DESC') bids = course.homework_commons.page(params[:page] || 1).per(20).order('created_at DESC')
bids = bids.like(params[:name]) if params[:name].present? bids = bids.like(params[:name]) if params[:name].present?
homeworks = [] homeworks = []
bids.each do |bid| bids.each do |bid|
homeworks << show_homework_info(course,bid,current_user,is_course_teacher(current_user,course)) homeworks << show_homework_info(course,bid,current_user,is_course_teacher(current_user,course))
end end
homeworks homeworks
else else
raise '403' raise '403'
end end
@ -411,10 +435,10 @@ class CoursesService
#每个作业中学生最后提交的作业 #每个作业中学生最后提交的作业
homeworks = [] homeworks = []
course.homework_commons.each do |bid| course.homework_commons.each do |bid|
homework_attach = bid.student_works.order('updated_at DESC').first homework_attach = bid.student_works.order('updated_at DESC').first
unless homework_attach.nil? unless homework_attach.nil?
homeworks << homework_attach homeworks << homework_attach
end end
end end
unless homeworks.count == 0 unless homeworks.count == 0
homeworks.sort!{|order,newer| newer.updated_at <=> order.updated_at} homeworks.sort!{|order,newer| newer.updated_at <=> order.updated_at}
@ -433,21 +457,21 @@ class CoursesService
result result
end end
# 课程课件 # 课程课件
def course_attachments params def course_attachments params
result = [] result = []
course = Course.find(params[:course_id]) course = Course.find(params[:course_id])
attachments = course.attachments.order("created_on ") attachments = course.attachments.order("created_on ")
if !params[:name].nil? && params[:name] != "" if !params[:name].nil? && params[:name] != ""
attachments.each do |atta| attachments.each do |atta|
result << atta if atta.filename.include?(params[:name]) result << atta if atta.filename.include?(params[:name])
end end
else else
result = attachments result = attachments
end end
result result
end end
# 课程学生列表 # 课程学生列表
def course_members params def course_members params
@ -488,20 +512,20 @@ class CoursesService
end end
def del_assitant_teacher params def del_assitant_teacher params
member = Member.where("user_id = ? and course_id = ?",params[:user_id],params[:course_id]) member = Member.where("user_id = ? and course_id = ?",params[:user_id],params[:course_id])
member.each do |m| member.each do |m|
m.destroy m.destroy
end end
user_admin = CourseInfos.where("user_id = ? and course_id = ?",params[:user_id], params[:course_id]) user_admin = CourseInfos.where("user_id = ? and course_id = ?",params[:user_id], params[:course_id])
if user_admin.size > 0 if user_admin.size > 0
user_admin.each do |user| user_admin.each do |user|
user.destroy user.destroy
end end
end end
joined = StudentsForCourse.where('student_id = ? and course_id = ?', params[:user_id],params[:course_id]) joined = StudentsForCourse.where('student_id = ? and course_id = ?', params[:user_id],params[:course_id])
joined.each do |join| joined.each do |join|
join.delete join.delete
end end
end end
def create_course_notice params ,current_user def create_course_notice params ,current_user
@ -570,11 +594,11 @@ class CoursesService
:open_anonymous_evaluation => open_anonymous_evaluation, :open_anonymous_evaluation => open_anonymous_evaluation,
#:homework_for_anonymous_comments => homework_for_anonymous_comments, #:homework_for_anonymous_comments => homework_for_anonymous_comments,
:created_on => bid.created_at,:deadline => bid.end_time, :created_on => bid.created_at,:deadline => bid.end_time,
:homework_notsubmit_num => bid.course.members.count - bid.student_works.count, :homework_notsubmit_num => bid.course.members.count - bid.student_works.count,
:homework_submit_num => bid.student_works.count, :homework_submit_num => bid.student_works.count,
:homework_status_student => get_homework_status( bid),:homework_status_teacher => homework_status_desc( bid), :homework_status_student => get_homework_status( bid),:homework_status_teacher => homework_status_desc( bid),
:student_evaluation_part => get_evaluation_part( bid ,3), :student_evaluation_part => get_evaluation_part( bid ,3),
:ta_evaluation_part => get_evaluation_part( bid ,2),:homework_anony_type => bid.homework_type == 1 && !bid.homework_detail_manual.nil?} :ta_evaluation_part => get_evaluation_part( bid ,2),:homework_anony_type => bid.homework_type == 1 && !bid.homework_detail_manual.nil?}
end end
@ -586,9 +610,9 @@ class CoursesService
homework_count = bid.homeworks.count #已提交的作业数量 homework_count = bid.homeworks.count #已提交的作业数量
student_questions_count = bid.journals_for_messages.where('m_parent_id IS NULL').count student_questions_count = bid.journals_for_messages.where('m_parent_id IS NULL').count
description = bid.description description = bid.description
#if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2 #if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2
state = bid.comment_status state = bid.comment_status
#end #end
open_anonymous_evaluation = bid.open_anonymous_evaluation open_anonymous_evaluation = bid.open_anonymous_evaluation
{:course_name => course.name,:id => bid.id, :course_teacher => author, :homework_times => many_times, :homework_name => name, :homework_count => homework_count,:student_questions_count => student_questions_count, {:course_name => course.name,:id => bid.id, :course_teacher => author, :homework_times => many_times, :homework_name => name, :homework_count => homework_count,:student_questions_count => student_questions_count,
:description => description, :homework_state => state,:open_anonymous_evaluation => open_anonymous_evaluation} :description => description, :homework_state => state,:open_anonymous_evaluation => open_anonymous_evaluation}
@ -685,12 +709,12 @@ class CoursesService
latest_course_dynamics << {:time => latest_news.first.created_on } latest_course_dynamics << {:time => latest_news.first.created_on }
end end
# 课程讨论区 # 课程讨论区
latest_message = course.boards.first.topics.page(1).per(2) latest_message = course.boards.first.topics.page(1).per(2)
unless latest_message.first.nil? unless latest_message.first.nil?
topic_count = course.boards.nil? ? 0 : course.boards.first.topics.count topic_count = course.boards.nil? ? 0 : course.boards.first.topics.count
topics = latest_message.all topics = latest_message.all
latest_course_dynamics << {:time => latest_message.first.created_on} latest_course_dynamics << {:time => latest_message.first.created_on}
end end
# 课程资源 # 课程资源
# latest_attachment = course.attachments.order("created_on desc").page(1).per(2) # latest_attachment = course.attachments.order("created_on desc").page(1).per(2)
# unless latest_attachment.first.nil? # unless latest_attachment.first.nil?
@ -727,29 +751,29 @@ class CoursesService
unless active_students.empty? unless active_students.empty?
latest_course_dynamics <<{:time=>"1970-01-01 0:0:0 +0800"} latest_course_dynamics <<{:time=>"1970-01-01 0:0:0 +0800"}
end end
latest_course_dynamic = latest_course_dynamics.first latest_course_dynamic = latest_course_dynamics.first
unless latest_course_dynamic.nil? unless latest_course_dynamic.nil?
result << {:course_name => course.name, result << {:course_name => course.name,
:current_user_is_member => current_user.member_of_course?(course), :current_user_is_member => current_user.member_of_course?(course),
:current_user_is_teacher => is_course_teacher(current_user,course), :current_user_is_teacher => is_course_teacher(current_user,course),
:course_id => course.id, :course_id => course.id,
:course_img_url => url_to_avatar(course), :course_img_url => url_to_avatar(course),
:course_time => course.time, :course_time => course.time,
:course_term => course.term, :course_term => course.term,
:news_count => notices_count, :news_count => notices_count,
:homework_count => homework_count, :homework_count => homework_count,
:topic_count => topic_count, :topic_count => topic_count,
:news => notices, :news => notices,
:homeworks => homeworkss, :homeworks => homeworkss,
:topics => topics, :topics => topics,
:better_students => better_students, :better_students => better_students,
:active_students => active_students, :active_students => active_students,
:message => "", :message => "",
:course_student_num=>course ? course.members.count : 0, :course_student_num=>course ? course.members.count : 0,
#:time_from_now=> distance_of_time_in_words(Time.now, latest_course_dynamic[:time].to_time) << "前", #:time_from_now=> distance_of_time_in_words(Time.now, latest_course_dynamic[:time].to_time) << "前",
:time_from_now=>time_from_now(latest_course_dynamic[:time].to_time), #.strftime('%Y-%m-%d %H:%M:%S').to_s, :time_from_now=>time_from_now(latest_course_dynamic[:time].to_time), #.strftime('%Y-%m-%d %H:%M:%S').to_s,
:time=>latest_course_dynamic[:time].to_time} :time=>latest_course_dynamic[:time].to_time}
end end
end end
#返回数组集合 #返回数组集合
@ -768,9 +792,9 @@ class CoursesService
sql = "select users.*,ROUND(sum(student_works.final_score),2) score from student_works left outer join users on student_works.user_id = users.id" << sql = "select users.*,ROUND(sum(student_works.final_score),2) score from student_works left outer join users on student_works.user_id = users.id" <<
" where homework_common_id in ( select id from homework_commons where homework_commons.course_id = #{params[:course_id]}) GROUP BY student_works.user_id ORDER BY score desc limit #{page*10},10" " where homework_common_id in ( select id from homework_commons where homework_commons.course_id = #{params[:course_id]}) GROUP BY student_works.user_id ORDER BY score desc limit #{page*10},10"
sql_count = " select count(distinct(student_works.user_id) ) " << sql_count = " select count(distinct(student_works.user_id) ) " <<
" from student_works left outer join users on student_works.user_id = users.id " << " from student_works left outer join users on student_works.user_id = users.id " <<
" where homework_common_id in " << " where homework_common_id in " <<
" ( select id from homework_commons where homework_commons.course_id = #{params[:course_id]}) " " ( select id from homework_commons where homework_commons.course_id = #{params[:course_id]}) "
max_size = ActiveRecord::Base.connection().select_value(sql_count) max_size = ActiveRecord::Base.connection().select_value(sql_count)
user_list = User.find_by_sql(sql) user_list = User.find_by_sql(sql)
else else

@ -1,25 +1,29 @@
<% if @object_id && @state != 6%> <% if @object_id && @state != 6 && @state !=4 %>
$("#join_in_course_header").html("<%= escape_javascript(join_in_course_header(@course, @user)) %>"); $("#join_in_course_header").html("<%= escape_javascript(join_in_course_header(@course, @user)) %>");
<% end %> <% end %>
<% if @state %> <% if @state %>
<% if @state == 0 %> <% if @state == 0 %>
alert("加入成功"); alert("加入成功");
hideModal($("#popbox02")); hideModal($("#popbox02"));
$("#try_join_course_link").replaceWith("<a href='<%=url_for(:controller => 'homework_common', :action => 'index',:course=>course.id, :host=>Setting.host_course)%>' target='_blank' class='blue_n_btn fr mt20'>提交作品</a>"); $("#try_join_course_link").replaceWith("<a href='<%=url_for(:controller => 'homework_common', :action => 'index',:course=>@course.id, :host=>Setting.host_course)%>' target='_blank' class='blue_n_btn fr mt20'>提交作品</a>");
window.location.href= "http://"+"<%= Setting.host_name%>"+"/courses/" + "<%= course.id%>" window.location.href= "http://"+"<%= Setting.host_name%>"+"/courses/" + "<%= @course.id%>"
<% elsif @state == 1 %> <% elsif @state == 1 %>
alert("密码错误"); alert("密码错误");
<% elsif @state == 2 %> <% elsif @state == 2 %>
alert("课程已过期\n请联系课程管理员重启课程。(在配置课程处)"); alert("课程已过期\n请联系课程管理员重启课程。(在配置课程处)");
<% elsif @state == 3 %> <% elsif @state == 3 %>
alert("您已经加入了课程"); alert("您已经加入了课程");
window.location.href= "http://"+"<%= Setting.host_name%>"+"/courses/" + "<%= course.id%>" window.location.href= "http://"+"<%= Setting.host_name%>"+"/courses/" + "<%= @course.id%>"
<% elsif @state == 4 %> <% elsif @state == 4 %>
alert("您加入的课程不存在"); alert("您加入的课程不存在");
<% elsif @state == 5 %> <% elsif @state == 5 %>
alert("您还未登录"); alert("您还未登录");
<% elsif @state == 6 %> <% elsif @state == 6 %>
alert("申请成功,请等待审核") alert("申请成功,请等待审核")
hideModal($("#popbox02"));
<% elsif @state == 7%>
alert("您已经发送过申请了,请耐心等待")
hideModal($("#popbox02"));
<% else %> <% else %>
alert("未知错误,请稍后再试"); alert("未知错误,请稍后再试");
<% end %> <% end %>

@ -139,6 +139,10 @@
<div id="homeworkDetailShow" class="fr" style="display:none;"><a href="javascript:void(0);" class="linkBlue">[展开]</a></div> <div id="homeworkDetailShow" class="fr" style="display:none;"><a href="javascript:void(0);" class="linkBlue">[展开]</a></div>
<div id="homeworkDetailHide" class="fr" style="display:none;"><a href="javascript:void(0);" class="linkBlue">[收起]</a></div> <div id="homeworkDetailHide" class="fr" style="display:none;"><a href="javascript:void(0);" class="linkBlue">[收起]</a></div>
<div class="cl"></div> <div class="cl"></div>
<div>
<%= render :partial => 'student_work/work_attachments', :locals => {:attachments => @homework.attachments} %>
<div class="cl"></div>
</div>
<div class="mt5"> <div class="mt5">
<div class="fontGrey2 db fl">截止时间:<%= @homework.end_time %></div> <div class="fontGrey2 db fl">截止时间:<%= @homework.end_time %></div>
<% if @homework.homework_detail_manual%> <% if @homework.homework_detail_manual%>

@ -16,6 +16,19 @@
$(this).addClass("referenceTypeActive"); $(this).addClass("referenceTypeActive");
}); });
}); });
// 点击 checkbox选中引用的资源的时候保存该资源的id到session里去
function store_seleted_resource(dom){
if(dom.attr('checked') == 'checked' ){
$.get(
'<%= store_selected_resource_user_path %>'+'?save=y&res_id='+dom.val()
)
}else {
$.get(
'<%= store_selected_resource_user_path %>'+'?save=n&res_id='+dom.val()
)
}
}
</script> </script>
<!--<div class="referenceResourcesPopup">--> <!--<div class="referenceResourcesPopup">-->
<div> <div>

@ -1,13 +1,13 @@
<% unless @attachments.empty?%> <% unless @attachments.empty?%>
<% @attachments.each_with_index do |attachment, i| %> <% @attachments.each do |attachment| %>
$("#attachments_fields").append( $("#attachments_fields").append(
'<span id="attachments_p<%= i %>">'+ '<span id="attachments_p<%= attachment.id %>">'+
'<%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => "filename link_file", :readonly=>"readonly")%>'+ '<%= text_field_tag("attachments[p#{attachment.id}][filename]", attachment.filename, :class => "filename link_file", :readonly=>"readonly")%>'+
'<%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => "description", :style=>"display: inline-block;") %>'+ '<%= text_field_tag("attachments[p#{attachment.id}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => "description", :style=>"display: inline-block;") %>'+
'<span class="ispublic-label"><%= l(:field_is_public)%>:</span>'+ '<span class="ispublic-label"><%= l(:field_is_public)%>:</span>'+
'<%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false,:class => "is_public")%>'+ '<%= check_box_tag("attachments[p#{attachment.id}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false,:class => "is_public")%>'+
'<%= link_to("&nbsp;".html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => "js"), :method => "delete", :remote => true, :class => "remove-upload") unless attachment.id.nil? %>'+ '<%= link_to("&nbsp;".html_safe, attachment_path(attachment, :attachment_id => "p#{attachment.id}", :format => "js"), :method => "delete", :remote => true, :class => "remove-upload") unless attachment.id.nil? %>'+
'<%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %>'+ '<%= hidden_field_tag "attachments[p#{attachment.id}][token]", "#{attachment.token}" %>'+
'</span>'+ '</span>'+
'<div class="cl"></div>') '<div class="cl"></div>')

@ -1045,6 +1045,8 @@ a.pro_mes_w{ height:20px; display:block; color:#999999;}
.rside_work_con{ width:650px;} .rside_work_con{ width:650px;}
a.c_grey{ color:#999999;} a.c_grey{ color:#999999;}
a:hover.c_grey{ color:#333;} a:hover.c_grey{ color:#333;}
a.link_file_a{ background:url(../images/pic_file.png) 0 2px no-repeat; padding-left:20px; }
a:hover.link_file_a{ background:url(../images/pic_file.png) 0 -25px no-repeat; color:#3ca5c6;}
.link_file_a{ display:block; max-width:450px;overflow:hidden; white-space: nowrap; text-overflow:ellipsis;} .link_file_a{ display:block; max-width:450px;overflow:hidden; white-space: nowrap; text-overflow:ellipsis;}
.last_time{width:auto; text-align:right; margin-right:70px;} .last_time{width:auto; text-align:right; margin-right:70px;}
.link_file_box{ width:360px;} .link_file_box{ width:360px;}

Loading…
Cancel
Save