diff --git a/.gitignore b/.gitignore index 22d9e17e6..0727a920a 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ vendor/cache /public/files /tags /config/initializers/gitlab_config.rb +1234567 diff --git a/1234567 b/1234567 deleted file mode 100644 index ed94d1804..000000000 --- a/1234567 +++ /dev/null @@ -1 +0,0 @@ -{"access_token":"q51KZUeA6_-CCCH-Buy1m4pR7G9hh-9GT_Vn-h9oFq8qfF9SVVeagJZ7Jeuvv3k12UEXk7IxtAuXkrBlufaanGd81bNEEkXkPyhPveTHenmjj5fQa3GQmxCM9kUPhZjyXMPjCIAKZC","expires_in":7200,"got_token_at":1464146250} \ No newline at end of file diff --git a/Client.html b/Client.html deleted file mode 100644 index fbb7cec52..000000000 --- a/Client.html +++ /dev/null @@ -1,25 +0,0 @@ - - -
-photo Share A
-Text Share B
-Text Share C
-#{ll(Setting.default_language, :text_user_wrote, User.find(@org_comment.creator_id).realname)}".html_safe + respond_to do | format| + format.js + end + end + + def reply + @document = OrgDocumentComment.find(params[:id]).root + @quote = params[:quote][:quote] + @org_document = OrgDocumentComment.new(:creator_id => User.current.id, :reply_id => params[:id]) + + # params[:blog_comment][:sticky] = params[:blog_comment][:sticky] || 0 + # params[:blog_comment][:locked] = params[:blog_comment][:locked] || 0 + @org_document.title = params[:org_document_comment][:title] + @org_document.content = params[:org_document_comment][:content] + @org_document.content = @quote + @org_document.content + #@org_document.title = "RE: #{@article.title}" unless params[:blog_comment][:title] + @document.children << @org_document + # @user_activity_id = params[:user_activity_id] + # user_activity = UserActivity.where("act_type='BlogComment' and act_id =#{@article.id}").first + # if user_activity + # user_activity.updated_at = Time.now + # user_activity.save + # end + # attachments = Attachment.attach_files(@org_document, params[:attachments]) + # render_attachment_warning_if_needed(@org_document) + #@article.save + # redirect_to user_blogs_path(:user_id=>params[:user_id]) + respond_to do |format| + format.html { + # if params[:course_id] #如果呆了course_id过来了,那么这是要跳到课程大纲去的 + # redirect_to syllabus_course_path(:id=>params[:course_id]) + # else + redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id) + # end + + } + format.js + end + end + + private + def find_subdomain_and_subfield + @subdomain = SubDomain.find(params[:sub_domain_id]) + @org_subfield = OrgSubfield.find(params[:org_subfield_id]) + @organization = @org_subfield.organization + rescue ActiveRecord::RecordNotFound + # source_subdomain_subfield not found + render_404 + end + + def find_subfield_content + @subfield_content = @organization.org_subfields.order("priority") + end +end diff --git a/app/controllers/sub_domains_controller.rb b/app/controllers/sub_domains_controller.rb new file mode 100644 index 000000000..e32935789 --- /dev/null +++ b/app/controllers/sub_domains_controller.rb @@ -0,0 +1,63 @@ +class SubDomainsController < ApplicationController + layout 'base_org' + before_filter :find_org_subfield_and_subdomain, :only => [:show, :index, :domain_update_priority, :destroy, :update, :hide_sub_domain, :show_sub_domain] + + def new + @subdomain = SubDomain.new + @org_subfield = OrgSubfield.find(params[:org_subfield_id]) + @organization = @org_subfield.organization + end + + def create + if SubDomain.where("org_subfield_id=#{params[:org_subfield_id]} and name=?",params[:name]).count == 0 + @res = true + @subfield = OrgSubfield.find(params[:org_subfield_id]) + @organization = @subfield.organization + @subdomain = SubDomain.create(:name => params[:name], :org_subfield_id => params[:org_subfield_id], :priority => @subfield.sub_domains.blank? ? 1 : @subfield.sub_domains.order("priority").last.priority + 1) + @subdomain.update_column(:field_type, params[:field_type]) + else + @res = false + end + end + + def update + @subdomain.update_column(:name, params[:name]) + end + + def domain_update_priority + @subdomain.update_attribute(:priority, params[:priority].to_i) + end + + def destroy + @subdomain.destroy + end + + def show + render_404 + # @subfield_content = @organization.org_subfields.order("priority") + # render layout: @organization.switch_type ? 'base_sub_domain' : 'base_org' + end + + def index + + end + + def hide_sub_domain + @subdomain.update_attribute(:hide, 1) + end + + def show_sub_domain + @subdomain.update_attribute(:hide, 0) + end + + + private + def find_org_subfield_and_subdomain + @subfield = OrgSubfield.find(params[:org_subfield_id]) + @subdomain = SubDomain.find(params[:id]) + @organization = @subfield.organization + rescue ActiveRecord::RecordNotFound + # source_subdomain not found + render_404 + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a15f37274..121b93dc5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -41,7 +41,7 @@ class UsersController < ApplicationController :activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index, :activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource, :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction, - :user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course] + :user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist] before_filter :auth_user_extension, only: :show #before_filter :rest_user_score, only: :show #before_filter :select_entry, only: :user_projects @@ -85,6 +85,29 @@ class UsersController < ApplicationController helper :issues include UsersHelper + #展开所有回复 + def show_all_replies + @comment = JournalsForMessage.find params[:comment].to_i + end + + #二级回复 + def reply_to + case params[:type] + when 'HomeworkCommon' + @reply = JournalsForMessage.find params[:reply_id] + if params[:user_activity_id] + @user_activity_id = params[:user_activity_id] + else + @user_activity_id = -1 + end + @is_in_course = params[:is_in_course] + @course_activity = params[:course_activity].to_i + end + respond_to do |format| + format.js + end + end + def refresh_changests if !(@user.nil?) && !(@user.memberships.nil?) @user.memberships.each do |member| @@ -288,6 +311,52 @@ class UsersController < ApplicationController end end + # 处理资源引用请求 + # status + def deal_with_apply_resource + @msg = CourseMessage.find(params[:msg_id]) + ar = ApplyResource.where("id = ?", @msg.course_message_id).first + unless ar.nil? + case params[:agree] + when 'Y' + ar.update_column('status', 2) + @msg.update_attributes(:apply_result => 1, :viewed => 1) + ar.course_messages << CourseMessage.new(:user_id => ar.user_id, :course_id => -1, :viewed => false, :apply_result => 2, :status => 1) + when 'N' + ar.update_column('status', 3) + @msg.update_attributes(:apply_result => 2, :viewed => 1) + ar.course_messages << CourseMessage.new(:user_id => ar.user_id, :course_id => -1, :viewed => false, :apply_result => 3, :status => 1) + end + end + respond_to do |format| + format.js + end + end + + #处理引用作业的请求 + #status 1 同意 2 拒绝 + def dealwith_apply_homework + @msg = CourseMessage.find(params[:msg_id]) + ah = ApplyHomework.where("user_id = ? and homework_common_id = ?",@msg.apply_user_id, @msg.course_message_id) + case params[:agree] + when 'Y' + unless ah.empty? + ah.first.update_column('status', 2) + CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>1) + @msg.update_attributes(:apply_result=>1,:viewed=>1) + end + when 'N' + unless ah.empty? + ah.first.update_column('status', 3) + CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>2) + @msg.update_attributes(:apply_result=>2,:viewed=>1) + end + end + respond_to do |format| + format.js + end + end + # added by bai def show_score @@ -372,13 +441,85 @@ class UsersController < ApplicationController end # end + # 资源分享请求弹框 + def apply_resource + if User.current.logged? + @attachment = Attachment.find params[:attachment_id] + @state = 2 + else + @state = 1 + end + respond_to do |format| + format.js + end + end + + #引用作业请求弹框 + def apply_homework + if User.current.logged? + @homework = HomeworkCommon.find params[:homework_id] + @state = 2 + else + @state = 1 + end + respond_to do |format| + format.js + end + end + + # 申请引用资源 + def apply_for_resource + if User.current.logged? + @attachment = Attachment.where("id =?", params[:attachment_id].to_i).first + unless @attachment.nil? + ar = ApplyResource.where("user_id = ? and attachment_id = ?", User.current.id, params[:attacment_id].to_i) + if ar.empty? + ApplyResource.create(:user_id => params[:id].to_i, :attachment_id => params[:attachment_id].to_i, :status => true, :container_id => @attachment.container_id, :container_type => @attachment.container_type, :content => params[:content], :apply_user_id => @attachment.author_id) + @state = 2 + else + @state = 3 + end + end + else + @state = 1 + end + respond_to do |format| + format.js + end + end + + #申请引用非公开作业 + def apply_for_homework + if User.current.logged? + homework = HomeworkCommon.find params[:homework_id] + unless homework.nil? + ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", User.current.id, params[:homework_id].to_i) + if ah.empty? + ApplyHomework.create(:user_id => params[:id].to_i, :homework_common_id => params[:homework_id].to_i, :status => 1) + Mailer.run.apply_for_homework_request(homework, User.current) + CourseMessage.create(:user_id => homework.user_id, :course_id => homework.course.id, :viewed => false,:course_message_id=>params[:homework_id].to_i,:course_message_type=>'HomeworkCommon',:status=>5,:apply_user_id=>params[:id].to_i,:content=>params[:content]) + @state = 2 + @ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", params[:id].to_i, params[:homework_id].to_i).first + @homework = homework + else + @state = 3 + end + end + else + @state = 1 + end + respond_to do |format| + format.js + end + end + #用户作业列表 def user_homeworks @order,@b_sort = params[:order] || "created_at",params[:sort] || "desc" @user = User.current @r_sort = @b_sort == "desc" ? "asc" : "desc" - if(params[:type].blank? || params[:type] == "1") #公共题库 - visible_course = Course.where("is_public = 1 && is_delete = 0") + if(params[:type].blank? || params[:type] == "1") #题库 + visible_course = Course.where("is_delete = 0") visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")" @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}") elsif params[:type] == "2" #我的题库 @@ -398,32 +539,40 @@ class UsersController < ApplicationController end def student_homeworks - if User.current == @user - @page = params[:page] ? params[:page].to_i + 1 : 0 - user_course_ids = @user.courses.empty? ? "(-1)" :"(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" - - #判断当前用户在当前课程的身份 - visibleCourse = @user.courses.empty? ? [] : @user.courses.visible - homework_ids = [] - visibleCourse.each do |course| - homeworks = HomeworkCommon.where("course_id = #{course.id} and publish_time <= '#{Date.today}'") - homework_ids << homeworks.pluck(:id) unless homeworks.empty? - end - visible_homework_ids = homework_ids.size == 0 ? "(-1)" :"(" + homework_ids.join(",") + ")" - @homework_commons = HomeworkCommon.where("id in #{visible_homework_ids}").order("created_at desc").limit(10).offset(@page * 10) - @is_teacher = User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true) - @is_in_course = params[:is_in_course].to_i || 0 - respond_to do |format| - format.js - format.html {render :layout => 'new_base_user'} - end - else - render_403 + if User.current == @user + @page = params[:page] ? params[:page].to_i + 1 : 0 + user_course_ids = @user.courses.empty? ? "(-1)" :"(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" + + #判断当前用户在当前课程的身份 + visibleCourse = @user.courses.empty? ? [] : @user.courses.where("is_delete = 0").visible + homework_ids = [] + visibleCourse.each do |course| + homeworks = HomeworkCommon.where("course_id = #{course.id} and publish_time <= '#{Date.today}'") + homework_ids << homeworks.pluck(:id) unless homeworks.empty? + end + visible_homework_ids = homework_ids.size == 0 ? "(-1)" :"(" + homework_ids.join(",") + ")" + @homework_commons = HomeworkCommon.where("id in #{visible_homework_ids}").order("created_at desc").limit(10).offset(@page * 10) + @is_teacher = User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true) + @is_in_course = params[:is_in_course].to_i || 0 + respond_to do |format| + format.js + format.html {render :layout => 'new_base_user'} end + else + render_403 + end end def choose_user_course homework = HomeworkCommon.find params[:send_id].to_i + if homework.user != User.current && homework.course.is_public == 0 && !User.current.allowed_to?(:as_teacher,homework.course) + ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", User.current.id, params[:send_id].to_i) + if ah.empty? + @status = 2 + elsif ah.first.status != 2 + @status = ah.first.status + end + end if !params[:search].nil? search = "%#{params[:search].to_s.strip.downcase}%" @course = @user.courses.where("is_delete = 0 and #{Course.table_name}.id != #{homework.course_id} and #{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p",:p=>search).select { |course| @user.allowed_to?(:as_teacher,course)} @@ -496,7 +645,7 @@ class UsersController < ApplicationController new_homework.homework_detail_programing.save if new_homework.homework_detail_programing new_homework.homework_detail_group.save if new_homework.homework_detail_group end - homework.update_attribute(:quotes, homework.quotes+1) + homework.update_column(:quotes, homework.quotes+1) end @homework = homework respond_to do |format| @@ -528,19 +677,40 @@ class UsersController < ApplicationController @order,@b_sort = params[:order] || "created_at",params[:sort] || "desc" @r_sort = @b_sort == "desc" ? "asc" : "desc" @user = User.current - if(params[:type].blank? || params[:type] == "1") #公共题库 - visible_course = Course.where("is_public = 1 && is_delete = 0") + if(params[:type].blank? || params[:type] == "1") #题库 + if params[:is_import].to_i == 1 + visible_course = Course.where("is_public = 1 && is_delete = 0") + elsif params[:is_import].to_i == 0 + visible_course = Course.where("is_delete = 0") + end visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")" @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}") elsif params[:type] == "2" #我的题库 - @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}") - end - if params[:property] && params[:property] == "1" - @homeworks = @homeworks.where("homework_type = 1").reorder("#{@order} #{@b_sort}") - elsif params[:property] && params[:property] == "2" - @homeworks = @homeworks.where("homework_type = 2").reorder("#{@order} #{@b_sort}") - elsif params[:property] && params[:property] == "3" - @homeworks = @homeworks.where("homework_type = 3").reorder("#{@order} #{@b_sort}") + courses = @user.courses.where("is_delete = 1") + course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")" + @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and course_id not in #{course_ids}").order("#{@order} #{@b_sort}") + elsif params[:type] == "3" #申请题库 + none_visible_course = Course.where("is_delete = 1") + none_visible_course_ids = none_visible_course.empty? ? "(-1)" : "(" + none_visible_course.map{|course| course.id}.join(",") + ")" + #apply_homeworks = ApplyHomework.where("user_id = ?",@user.id).order('created_at desc') + #homework_ids = apply_homeworks.empty? ? "(-1)" : "(" + apply_homeworks.map{|ah| ah.homework_common_id}.join(",") + ")" + #@homeworks = HomeworkCommon.where("id in #{homework_ids} and course_id not in #{none_visible_course_ids}") + + sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN apply_homeworks as ah ON homework_commons.id = ah.homework_common_id where ah.user_id = #{@user.id} and homework_commons.course_id not in #{none_visible_course_ids} order by ah.created_at desc" + @homeworks = HomeworkCommon.find_by_sql(sql) + end + if params[:property] + all_homework_ids = @homeworks.empty? ? "(-1)" : "(" + @homeworks.map{|h| h.id}.join(",") + ")" + if params[:property] == "1" + @homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 1") + #@homeworks = @homeworks.where("homework_type = 1").reorder("#{@order} #{@b_sort}") + elsif params[:property] == "2" + @homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 2") + #@homeworks = @homeworks.where("homework_type = 2").reorder("#{@order} #{@b_sort}") + elsif params[:property] == "3" + @homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 3") + #@homeworks = @homeworks.where("homework_type = 3").reorder("#{@order} #{@b_sort}") + end end @type = params[:type] @property = params[:property] @@ -557,7 +727,21 @@ class UsersController < ApplicationController end def show_homework_detail - @homework = HomeworkCommon.find params[:homework].to_i + homework = HomeworkCommon.find params[:homework].to_i + if homework.course.is_public == 0 && !User.current.allowed_to?(:as_teacher,homework.course) && User.current != homework.user + ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", User.current.id, params[:homework].to_i) + if ah.empty? + @status = 2 + @homework = nil + elsif ah.first.status != 2 + @status = ah.first.status + @homework = nil + elsif ah.first.status == 2 + @homework = homework + end + else + @homework = homework + end @is_import = params[:is_import] respond_to do |format| format.js @@ -571,8 +755,12 @@ class UsersController < ApplicationController @user = User.current search = params[:name].to_s.strip.downcase type_ids = params[:property]=="" || params[:property].nil? ? "(1, 2, 3)" : "(" + params[:property] + ")" - if(params[:type].blank? || params[:type] == "1") #全部 - visible_course = Course.where("is_public = 1 && is_delete = 0") + if(params[:type].blank? || params[:type] == "1") #全部 + if params[:is_import].to_i == 1 + visible_course = Course.where("is_public = 1 && is_delete = 0") + elsif params[:is_import].to_i == 0 + visible_course = Course.where("is_delete = 0") + end visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")" all_homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'") all_user_ids = all_homeworks.map{|hw| hw.user_id} @@ -586,14 +774,29 @@ class UsersController < ApplicationController else @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and homework_type in #{type_ids} and (name like '%#{search}%' or user_id in #{user_ids})").order("#{@order} #{@b_sort}") end - elsif params[:type] == "2" #课程资源 + elsif params[:type] == "2" #我的题库 + courses = @user.courses.where("is_delete = 1") + course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")" + if @order == "course_name" + sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where homework_commons.course_id not in #{course_ids} and homework_commons.user_id = #{@user.id} and homework_type in #{type_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%') order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}" + @homeworks = HomeworkCommon.find_by_sql(sql) + elsif @order == "user_name" + @homeworks = HomeworkCommon.where("user_id = #{@user.id} and course_id not in #{course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}") + else + @homeworks = HomeworkCommon.where("user_id = #{@user.id} and course_id not in #{course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").order("#{@order} #{@b_sort}") + end + elsif params[:type] == "3" #申请题库 + apply_homeworks = ApplyHomework.where("user_id = ?",@user.id) + homework_ids = apply_homeworks.empty? ? "(-1)" : "(" + apply_homeworks.map{|ah| ah.homework_common_id}.join(",") + ")" + none_visible_course = Course.where("is_delete = 1") + none_visible_course_ids = none_visible_course.empty? ? "(-1)" : "(" + none_visible_course.map{|course| course.id}.join(",") + ")" if @order == "course_name" - sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where homework_commons.user_id = #{@user.id} and homework_type in #{type_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%') order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}" + sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where courses.is_delete = 0 and homework_commons.id in #{homework_ids} and homework_type in #{type_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%') order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}" @homeworks = HomeworkCommon.find_by_sql(sql) elsif @order == "user_name" - @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}") + @homeworks = HomeworkCommon.where("homework_commons.id in #{homework_ids} and course_id not in #{none_visible_course_ids} and (name like '%#{search}%') and homework_type in #{type_ids}").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}") else - @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").order("#{@order} #{@b_sort}") + @homeworks = HomeworkCommon.where("id in #{homework_ids} and (name like '%#{search}%') and course_id not in #{none_visible_course_ids} and homework_type in #{type_ids}").order("#{@order} #{@b_sort}") end end =begin @@ -715,7 +918,7 @@ class UsersController < ApplicationController student_work.save send_message_to_teacher(student_work) - homework.update_attributes(:updated_at => Time.now) + homework.update_column(:updated_at, Time.now) update_course_activity(homework.class,homework.id) update_user_activity(homework.class,homework.id) update_org_activity(homework.class,homework.id) @@ -750,7 +953,11 @@ class UsersController < ApplicationController render_attachment_warning_if_needed(homework) homework_detail_manual = HomeworkDetailManual.new - homework_detail_manual.ta_proportion = homework.homework_type == 1 ? 0.6 : 0.3 + if homework.anonymous_comment == 1 + homework_detail_manual.ta_proportion = homework.homework_type == 1 ? 1.0 : 0.4 + else + homework_detail_manual.ta_proportion = homework.homework_type == 1 ? 0.6 : 0.3 + end if homework.publish_time > Date.today homework_detail_manual.comment_status = 0 else @@ -766,7 +973,11 @@ class UsersController < ApplicationController if homework.homework_type == 2 homework_detail_programing = HomeworkDetailPrograming.new homework.homework_detail_programing = homework_detail_programing - homework_detail_programing.ta_proportion = 0.5 + if homework.anonymous_comment == 1 + homework_detail_programing.ta_proportion = 0.6 + else + homework_detail_programing.ta_proportion = 0.5 + end homework_detail_programing.language = params[:language_type].to_i inputs = params[:program][:input] @@ -795,7 +1006,7 @@ class UsersController < ApplicationController homework_detail_group.save if homework_detail_group if params[:quotes] && !params[:quotes].blank? quotes_homework = HomeworkCommon.find params[:quotes].to_i - quotes_homework.update_attribute(:quotes, quotes_homework.quotes+1) + quotes_homework.update_column(:quotes, quotes_homework.quotes+1) end if params[:is_in_course] == "1" redirect_to homework_common_index_path(:course => homework.course_id) @@ -884,22 +1095,27 @@ class UsersController < ApplicationController #引入资源列表根据关键词过滤 def user_ref_resource_search - search = params[:search].to_s.strip.downcase - if(params[:type].blank? || params[:type] == "1") #全部 - user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 取交集并查询 - @attachments = Attachment.where("((author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ - " or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))) and (filename like '%#{search}%') ").order("created_on desc") - elsif params[:type] == "2" #课程资源 + if User.current.id.to_i != params[:id].to_i + render_403 + return + end + @resource_id = params[:mul_id] + @resource_type = params[:mul_type] + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" + @user = User.current + @switch_search = params[:search].nil? ? " " : params[:search] + search = "%#{@switch_search.strip.downcase}%" + # 别人的资源库是没有权限去看的 + if(params[:type] == "1") # 我的资源 + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} - @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) and (filename like '%#{search}%') ").order("created_on desc") - elsif params[:type] == "3" #项目资源 - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project' and (filename like '%#{search}%')").order("created_on desc") - elsif params[:type] == "4" #附件 - @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like '%#{search}%')").order("created_on desc") - elsif params[:type] == "5" #用户资源 - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Principal' and (filename like '%#{search}%')").order("created_on desc") - elsif params[:type] == "6" #公共资源 - @attachments = Attachment.where("(is_public =1 and is_publish = 1 and container_id is not null)" + "or (author_id = #{params[:id]} and is_publish = 0)").order("created_on desc") + user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } + # user_org_ids = User.current.organizations.map {|o| o.id} + @attachments = get_my_resources_search(params[:id], user_course_ids, user_project_ids, @order, @score, search) + elsif (params[:type].blank? || params[:type] == "6") # 公共资源 + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search) end @type = params[:type] @limit = 7 @@ -1216,9 +1432,9 @@ class UsersController < ApplicationController shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id) @page = params[:page] ? params[:page].to_i + 1 : 0 user_project_ids = (@user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" - user_course_ids = (@user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")" + user_course_ids = (@user.courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")" course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage')" - project_types = "('Message','Issue','ProjectCreateInfo')" + project_types = "('Message','Issue','Project')" principal_types = "JournalsForMessage" if params[:type].present? case params[:type] @@ -1731,7 +1947,7 @@ class UsersController < ApplicationController # 将资源发送到对应的课程,分为发送单个,或者批量发送 def add_exist_file_to_course @flag = true - if params[:send_id].present? + if params[:send_id].present? send_id = params[:send_id] @ori = Attachment.find_by_id(send_id) course_ids = params[:course_ids] @@ -1778,14 +1994,14 @@ class UsersController < ApplicationController end send_ids.each do |send_id| quotes = 0 - ori = Attachment.find_by_id(send_id) + @ori = Attachment.find_by_id(send_id) unless course_ids.nil? course_ids.each do |id| quotes = 0 - next if ori.blank? + next if @ori.blank? @exist = false Course.find(id).attachments.each do |att| #如果课程中包含该资源 - if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from + if att.id == @ori.id || (!att.copy_from.nil? && !@ori.copy_from.nil? && att.copy_from == @ori.copy_from) || att.copy_from == @ori.id || att.id == @ori.copy_from att.created_on = Time.now att.save @exist = true @@ -1793,21 +2009,21 @@ class UsersController < ApplicationController end end next if @exist - attach_copied_obj = ori.copy - attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 + attach_copied_obj = @ori.copy + attach_copied_obj.tag_list.add(@ori.tag_list) # tag关联 attach_copied_obj.container = Course.find(id) attach_copied_obj.created_on = Time.now attach_copied_obj.author_id = User.current.id attach_copied_obj.is_public = 0 - attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from + attach_copied_obj.copy_from = @ori.copy_from.nil? ? @ori.id : @ori.copy_from #发送要添加copy_from if attach_copied_obj.attachtype == nil attach_copied_obj.attachtype = 4 end if attach_copied_obj.save # 更新引用次数 - quotes = ori.quotes.to_i + 1 - ori.update_attribute(:quotes, quotes) unless ori.nil? - ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) + quotes = @ori.quotes.to_i + 1 + @ori.update_attribute(:quotes, quotes) unless @ori.nil? + @ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) end @save_message = attach_copied_obj.errors.full_messages end @@ -1847,6 +2063,18 @@ class UsersController < ApplicationController # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end + # elsif params[:type] == "2" + # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + # if params[:status] == "2" + # resource_type = "'Course'" + # elsif params[:status] == "3" + # resource_type = "'Project'" + # elsif params[:status] == "5" + # resource_type = "'Principal'" + # else + # resource_type = "'Project','OrgSubfield','Principal','Course'" + # end + # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) end @type = params[:type] @limit = 25 @@ -1988,6 +2216,18 @@ class UsersController < ApplicationController # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end + # elsif params[:type] == "2" + # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + # if params[:status] == "2" + # resource_type = "'Course'" + # elsif params[:status] == "3" + # resource_type = "'Project'" + # elsif params[:status] == "5" + # resource_type = "'Principal'" + # else + # resource_type = "'Project','OrgSubfield','Principal','Course'" + # end + # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) end @status = params[:status] @type = params[:type] @@ -2117,6 +2357,18 @@ class UsersController < ApplicationController # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end + # elsif params[:type] == "2" + # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + # if params[:status] == "2" + # resource_type = "'Course'" + # elsif params[:status] == "3" + # resource_type = "'Project'" + # elsif params[:status] == "5" + # resource_type = "'Principal'" + # else + # resource_type = "'Project','OrgSubfield','Principal','Course'" + # end + # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) end @type = params[:type] @limit = 25 @@ -2453,12 +2705,12 @@ class UsersController < ApplicationController # 获取公共资源 def get_public_resources user_course_ids, user_project_ids, order, score - attachments = Attachment.where("(is_publish = 1 and is_public =1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) ").order("#{order.nil? ? 'created_on' : order} #{score}") + attachments = Attachment.where("(is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) ").order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取公共资源搜索 def get_public_resources_search user_course_ids, user_project_ids, order, score, search - attachments = Attachment.where("is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course') and (filename like :p)" ,:p => search).order("#{order.nil? ? 'created_on' : order} #{score}") + attachments = Attachment.where("is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course') and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我的资源 @@ -2478,10 +2730,20 @@ class UsersController < ApplicationController # 获取我的课程资源 def get_course_resources author_id, user_course_ids, order, score attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Course')"+ - "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) + "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" ).order("#{order.nil? ? 'created_on' : order} #{score}") end + # # 获取我的私有资源分享结果 + # def get_my_private_resources apply_ids, resource_type, order, score + # attachments = Attachment.where("id in (#{apply_ids.empty? ? '0': apply_ids.join(',')}) and container_type in(#{resource_type})").order("#{order.nil? ? 'created_on' : order} #{score}") + # end + # + # # 获取我的私有资源分享搜索结果 + # def get_my_private_resources_search apply_ids, resource_type, order, score, search + # attachments = Attachment.where("id in (#{apply_ids.empty? ? '0': apply_ids.join(',')}) and container_type in(#{resource_type}) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") + # end + # 获取我的课程资源中搜索结果 def get_course_resources_search author_id, user_course_ids, order, score, search attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Course')"+ @@ -2502,7 +2764,7 @@ class UsersController < ApplicationController # 获取我的项目资源 def get_project_resources author_id, user_project_ids, order, score attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+ - "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) + "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)").order("#{order.nil? ? 'created_on' : order} #{score}") end @@ -2559,7 +2821,7 @@ class UsersController < ApplicationController # 获取我的用户类型资源 def get_principal_resources_public order, score - attchments = Attachment.where("container_type = 'Principal'and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") + attchments = Attachment.where("container_type = 'Principal' and is_public =1 and container_id is not null").order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我的用户类型资源 @@ -2570,7 +2832,7 @@ class UsersController < ApplicationController # 资源库 分为全部 课程资源 项目资源 附件 def user_resource # 别人的资源库是没有权限去看的 - if User.current.id.to_i != params[:id].to_i + if User.current.id.to_i != @user.id.to_i render_403 return end @@ -2579,7 +2841,7 @@ class UsersController < ApplicationController user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # user_org_ids = User.current.organizations.map {|o| o.id} - if(params[:type].blank? || params[:type] == "1") # 我的资源 + if( params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == "2" @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) @@ -2593,7 +2855,7 @@ class UsersController < ApplicationController # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) end - elsif params[:type] == "6" # 公共资源 + elsif (params[:type].blank? || params[:type] == "6") # 公共资源 if params[:status] == "2" @attachments = get_course_resources_public( user_course_ids, @order, @score) elsif params[:status] == "3" @@ -2606,6 +2868,18 @@ class UsersController < ApplicationController # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end + # elsif params[:type] == "2" # 私有资源 + # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + # if params[:status] == "2" + # resource_type = "'Course'" + # elsif params[:status] == "3" + # resource_type = "'Project'" + # elsif params[:status] == "5" + # resource_type = "'Principal'" + # else + # resource_type = "'Project','OrgSubfield','Principal','Course'" + # end + # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) end @status = params[:status] @type = params[:type] @@ -2625,13 +2899,12 @@ class UsersController < ApplicationController # 导入资源 def import_resources # 别人的资源库是没有权限去看的 - if User.current.id.to_i != params[:id].to_i + if User.current.id != params[:id].to_i render_403 return end @resource_id = params[:project_id].nil? ? (params[:course_id].nil? ? params[:subfield_file_id] : params[:course_id]) : params[:project_id] @resource_type = params[:project_id].nil? ? (params[:course_id].nil? ? "SubfieldFile" : "Course") : "Project" - @user = User.find(params[:id]) @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" @score = @b_sort == "desc" ? "asc" : "desc" user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} @@ -2784,8 +3057,21 @@ class UsersController < ApplicationController @attachments = get_principal_resources_public_search(@order, @score, search) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search) - end + @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search) + end + # elsif params[:type] == "2" # 私有资源 + # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + # if params[:status] == "2" + # resource_type = "'Course'" + # elsif params[:status] == "3" + # resource_type = "'Project'" + # elsif params[:status] == "5" + # resource_type = "'Principal'" + # else + # resource_type = "'Project','OrgSubfield','Principal','Course'" + # end + # @attachments = get_my_private_resources_search(apply_ids, resource_type, @order, @score, search) + # @attachments end @status = params[:status] @type = params[:type] @@ -2849,6 +3135,96 @@ class UsersController < ApplicationController end end + def user_courselist + @order, @c_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1 + + #确定 sort_type + if @order.to_i == @type.to_i + @c_sort = @c_sort.to_i == 1 ? 2 : 1 #1升序 2降序 + else + @c_sort = 2 + end + + sort_name = "updated_on" + sort_type = @c_sort == 1 ? "asc" : "desc" + + # @courses = @user.courses.visible.where("is_delete =?", 0).order("#{sort_name} #{sort_type}") + @courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS #{sort_name}").order("#{sort_name} #{sort_type}") + + #根据 作业+资源数排序 + if @order.to_i == 2 + @type = 2 + @courses.each do |course| + course[:infocount] = (User.current.admin? || User.current.allowed_to?(:as_teacher,course)) ? (course.homework_commons.count + visable_attachemnts_incourse(course).count) : (course.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(course).count) + if course[:infocount] < 0 + course[:infocount] = 0 + end + end + @c_sort == 1 ? (@courses = @courses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@courses = @courses.sort{|x,y| y[:infocount] <=> x[:infocount]}) + @courses = sortby_time_countcommon_nosticky @courses,sort_name + else + @type = 1 + end + + #分页 + @limit = 10 + @is_remote = true + @atta_count = @courses.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + @courses = paginateHelper @courses,@limit + + respond_to do |format| + format.js + format.html {render :layout => 'new_base_user'} + end + end + + def user_projectlist + @order, @c_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1 + + #确定 sort_type + if @order.to_i == @type.to_i + @c_sort = @c_sort.to_i == 1 ? 2 : 1 #1升序 2降序 + else + @c_sort = 2 + end + + sort_name = "updated_at" + sort_type = @c_sort == 1 ? "asc" : "desc" + + #@projects = @user.projects.visible.order("#{sort_name} #{sort_type}") + @projects = @user.projects.visible.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS #{sort_name} ").order("#{sort_name} #{sort_type}") + + #根据 问题+资源数排序 @project.project_score.issue_num @project.project_score.attach_num + if @order.to_i == 2 + @type = 2 + @projects.each do |project| + project[:infocount] = project.project_score.issue_num+project.project_score.attach_num + if project[:infocount] < 0 + project[:infocount] = 0 + end + end + @c_sort == 1 ? (@projects = @projects.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@projects = @projects.sort{|x,y| y[:infocount] <=> x[:infocount] }) + @projects = sortby_time_countcommon_nosticky @projects,sort_name + else + @type = 1 + end + + #分页 + @limit = 10 + @is_remote = true + @atta_count = @projects.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + @projects = paginateHelper @projects,@limit + + respond_to do |format| + format.js + format.html {render :layout => 'new_base_user'} + end + end + private def find_user diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index 0d75636f7..7ee0552fb 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -166,7 +166,7 @@ class WechatsController < ActionController::Base raise "非法操作, code不存在" unless params[:code] openid = get_openid_from_code(params[:code]) raise "无法获取到openid" unless openid - raise "此微信号已绑定用户, 不能得复绑定" if user_binded?(openid) + raise "此微信号已绑定用户, 不能重复绑定" if user_binded?(openid) user, last_login_on = User.try_to_login(params[:username], params[:password]) raise "用户名或密码错误,请重新登录" unless user @@ -178,7 +178,6 @@ class WechatsController < ActionController::Base openid: openid, user: user ) - request.reply.text "欢迎加入Trustie创新实践社区" render :json => {status:0, msg: "绑定成功"} rescue Exception=>e render :json => {status: -1, msg: e.message} @@ -211,7 +210,7 @@ class WechatsController < ActionController::Base user_project_ids = (@user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" user_course_ids = (@user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")" course_types = "('Message','News','HomeworkCommon','Poll','Course')" - project_types = "('Message','Issue','ProjectCreateInfo')" + project_types = "('Message','Issue','Project')" principal_types = "JournalsForMessage" blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index ed350ab51..fa084e349 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -276,7 +276,7 @@ class WordsController < ApplicationController ids = params[:asset_id].split(',') update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE end - @homework_common.update_column(:updated_at, Time.now) + @homework_common.update_column('updated_at', Time.now) update_course_activity(@homework_common.class,@homework_common.id) update_user_activity(@homework_common.class,@homework_common.id) update_org_activity(@homework_common.class,@homework_common.id) @@ -296,6 +296,40 @@ class WordsController < ApplicationController render_403 end end + + #作业的二级回复 + def reply_to_homework + if User.current.logged? + @user = User.current + reply = JournalsForMessage.find params[:id].to_i + @homework_common = HomeworkCommon.find reply.jour_id + if params[:reply_message].size>0 && User.current.logged? && @user + options = {:notes => params[:reply_message], :reply_id => reply.user_id,:user_id => @user.id,:m_parent_id => params[:id].to_i,:m_reply_id => params[:id].to_i} + feedback = HomeworkCommon.add_homework_jour(@user, params[:reply_message], reply.jour_id, options) + if (feedback.errors.empty?) + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE + end + @homework_common.update_column('updated_at', Time.now) + update_course_activity(@homework_common.class,@homework_common.id) + update_user_activity(@homework_common.class,@homework_common.id) + update_org_activity(@homework_common.class,@homework_common.id) + respond_to do |format| + format.js{ + @user_activity_id = params[:user_activity_id].to_i + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + } + end + else + flash[:error] = feedback.errors.full_messages[0] + end + end + else + render_403 + end + end def add_brief_introdution user = User.current diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 606c9b5fd..4d92808d4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -33,10 +33,46 @@ module ApplicationHelper extend Forwardable def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter + + # def user_blogs_path(resource,parameters={}) + # super + # end + + def update_visiti_count container container.update_column(:visits, container.visits + 1) end + def if_hidden_subdomain field + domains = field.sub_domains.select{|domain| domain.hide.to_i == 0} + result = domains.length > 0 ? true : false + return result + end + + # 判断某个资源是否可以申请 + def attach_show_allow attach_id + attachment = Attachment.find(attach_id) + case attachment.container_type + when "Project" + User.current.member_of?(attachment.container) ? true : false + when "Course" + User.current.member_of_course?(attachment.container) ? true : false + when "OrgSubfield" + User.current.member_of_org?(attachment.container.organization) ? true : false + when "Principal" + User.current.id == attachment.author_id ? true : false + end + end + + # 判断某个私有资源是否可以发送下载权限 + # 结果为true不能下载,false可以下载 + def private_attachment_allow attachment_id + attach = Attachment.find(attachment_id) + # 条件取否,result结果为true则不能下载 + result = attach.is_public == 0 && attach.author != User.current && !attach.get_apply_resource_status(attach.id, User.current.id) && !attach_show_allow(attach) + return result + end + # Time 2015-03-24 15:27:29 # Author lizanle # Description 从硬盘上删除对应的资源文件 @@ -76,11 +112,13 @@ module ApplicationHelper # 获取组织成员中文名字 def get_org_member_role_name member - case member.roles[0].name - when 'orgManager' - '管理人员' - when 'orgMember' - '组织成员' + unless member.roles[0].nil? + case member.roles[0].name + when 'orgManager' + '管理人员' + when 'orgMember' + '组织成员' + end end end @@ -123,7 +161,7 @@ module ApplicationHelper CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :homework_journal_num => 1) else score = course_contributor_score.homework_journal_num.to_i + 1 - course_contributor_score.update_attributes(:homework_journal_num => score) + course_contributor_score.update_column(:homework_journal_num, score) end # 课程留言 when "Course" @@ -131,42 +169,42 @@ module ApplicationHelper CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :journal_num => 1) else score = course_contributor_score.journal_num.to_i + 1 - course_contributor_score.update_attributes(:journal_num => score) + course_contributor_score.update_column(:journal_num, score) end when "Message" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 1) else score = course_contributor_score.message_num.to_i + 1 - course_contributor_score.update_attributes(:message_num => score) + course_contributor_score.update_column(:message_num, score) end when "MessageReply" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_reply_num => 1) else score = course_contributor_score.message_reply_num.to_i + 1 - course_contributor_score.update_attributes(:message_reply_num => score) + course_contributor_score.update_column(:message_reply_num, score) end when "NewReply" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_reply_num => 1) else score = course_contributor_score.news_reply_num.to_i + 1 - course_contributor_score.update_attributes(:news_reply_num => score) + course_contributor_score.update_column(:news_reply_num, score) end when "News" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_num => 1) else score = course_contributor_score.news_num.to_i + 1 - course_contributor_score.update_attributes(:news_num => score) + course_contributor_score.update_column(:news_num, score) end when "Attachment" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :resource_num => 1) else score = course_contributor_score.resource_num.to_i + 1 - course_contributor_score.update_attributes(:resource_num => score) + course_contributor_score.update_column(:resource_num, score) end end end @@ -178,38 +216,38 @@ module ApplicationHelper when "HomeworkCommon" unless course_contributor_score.nil? score = course_contributor_score.homework_journal_num.to_i - 1 - course_contributor_score.update_attribute(:homework_journal_num, score < 0 ? 0 : score) + course_contributor_score.update_column(:homework_journal_num, score < 0 ? 0 : score) end # 课程留言 when "Course" unless course_contributor_score.nil? score = course_contributor_score.journal_num.to_i - 1 - course_contributor_score.update_attribute(:journal_num, score < 0 ? 0 : score) + course_contributor_score.update_column(:journal_num, score < 0 ? 0 : score) end when "Message" unless course_contributor_score.nil? score = course_contributor_score.message_num.to_i - 1 - course_contributor_score.update_attribute(:message_num, score < 0 ? 0 : score) + course_contributor_score.update_column(:message_num, score < 0 ? 0 : score) end when "MessageReply" unless course_contributor_score.nil? score = course_contributor_score.message_reply_num.to_i - 1 - course_contributor_score.update_attribute(:message_reply_num, score < 0 ? 0 : score) + course_contributor_score.update_column(:message_reply_num, score < 0 ? 0 : score) end when "NewReply" unless course_contributor_score.nil? score = course_contributor_score.news_reply_num.to_i - 1 - course_contributor_score.update_attribute(:news_reply_num, score < 0 ? 0 : score) + course_contributor_score.update_column(:news_reply_num, score < 0 ? 0 : score) end when "News" unless course_contributor_score.nil? score = course_contributor_score.news_num.to_i - 1 - course_contributor_score.update_attribute(:news_num, score < 0 ? 0 : score) + course_contributor_score.update_column(:news_num, score < 0 ? 0 : score) end when "Attachment" unless course_contributor_score.nil? score = course_contributor_score.resource_num.to_i - 1 - course_contributor_score.update_attribute(:resource_num, score < 0 ? 0 : score) + course_contributor_score.update_column(:resource_num, score < 0 ? 0 : score) end end end @@ -2080,20 +2118,20 @@ module ApplicationHelper candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) elsif attachment.container.is_a?(Project) project = attachment.container - candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) + candown = User.current.member_of?(project) || (attachment.is_public == 1) || attachment.get_status_by_attach(User.current.id) == 2 elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board && attachment.container.board.project project = attachment.container.board.project candown = User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) elsif (attachment.container.has_attribute?(:course) ||attachment.container.has_attribute?(:course_id) ) && attachment.container.course course = attachment.container.course - candown = User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) + candown = User.current.member_of_course?(course) || (attachment.is_public == 1) || attachment.get_status_by_attach(User.current.id) == 2 elsif attachment.container.is_a?(Course) course = attachment.container - candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) + candown= User.current.member_of_course?(course) || (attachment.is_public == 1) || attachment.get_status_by_attach(User.current.id) == 2 elsif attachment.container.is_a?(OrgSubfield) org = attachment.container.organization - candown = User.current.member_of_org?(org) || (org.is_public && attachment.is_public == 1) + candown = User.current.member_of_org?(org) || (attachment.is_public == 1) || attachment.get_status_by_attach(User.current.id) == 2 elsif attachment.container.is_a?(OrgDocumentComment) org = attachment.container.organization candown = User.current.member_of_org?(org) || (org.is_public && attachment.is_public == 1) @@ -2953,6 +2991,14 @@ int main(int argc, char** argv){ return sort_projects end end + + def project_sort_first projects + unless projects.empty? + project_ids = '('+projects.map{|pro|pro.project_id}.join(',')+')' + sort_projects = ForgeActivity.find_by_sql("SELECT updated_at,user_id, project_id FROM forge_activities WHERE project_id IN #{project_ids} ORDER BY updated_at DESC limit 1") + return sort_projects + end + end end def user_url_in_org(user_id) @@ -2983,8 +3029,14 @@ def homework_common_index_url_in_org(course_id) Setting.protocol + "://" + Setting.host_name + "/homework_common?course=" + course_id.to_s end -def student_work_index_url_in_org(homework_id) - Setting.protocol + "://" + Setting.host_name + "/student_work?homework=" + homework_id.to_s +def student_work_index_url_in_org(homework_id, is_focus = '', show_work_id = '') + if is_focus != '' + Setting.protocol + "://" + Setting.host_name + "/student_work?homework=" + homework_id.to_s + "&is_focus=" + is_focus.to_s + elsif show_work_id != '' + Setting.protocol + "://" + Setting.host_name + "/student_work?homework=" + homework_id.to_s + "&show_work_id=" + show_work_id.to_s + else + Setting.protocol + "://" + Setting.host_name + "/student_work?homework=" + homework_id.to_s + end end def course_url_in_org(course_id) @@ -3061,10 +3113,155 @@ def host_with_protocol return Setting.protocol + "://" + Setting.host_name end +def secdomain_with_protocol secdomain + return Setting.protocol + "://" + secdomain + ".trustie.net" +end + + +#获取回复的所有父节点 +def get_reply_parents parents_rely, comment + unless comment.parent.nil? + parents_rely << comment.parent + get_reply_parents parents_rely, comment.parent + end + parents_rely +end + +#将有置顶属性的提到数组前面 +def sort_by_sticky topics + tmpTopics = [] + tmpIndex = 0 + topics.each do |topic| + if topic.sticky == 1 + tmpTopics[tmpIndex] = topic + tmpIndex = tmpIndex + 1 + end + end + + topics.each do |topic| + if topic.sticky == 0 + tmpTopics[tmpIndex] = topic + tmpIndex = tmpIndex + 1 + end + end + return tmpTopics +end + +#按人气排序的时候 相同的人气必须按某种时间顺序排序 有置顶属性 +def sortby_time_countcommon_hassticky topics,sortstr + tmpTopics = [] + tmpTopics = topics + tStart = -1 + tEnd = -1 + + tmpTopics_1 = [] + tmpIndex = 0 + + tmpTopics.each_with_index do |topic,index| + if topic.sticky == 0 + if tStart == -1 + if (index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount]) + tStart = index + end + else + if ((topic[:infocount] == tmpTopics[index-1][:infocount]) && ((index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount]))) + tEnd = index + else + if (topic[:infocount] == tmpTopics[index-1][:infocount]) + tEnd = index + end + if tEnd > tStart + for i in tStart..tEnd + tmpTopics_1[tmpIndex] = tmpTopics[i] + tmpIndex = tmpIndex + 1 + end + + if sortstr == "created_at" + tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_at].to_i <=> x[:created_at].to_i } + elsif sortstr == "created_on" + tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_on].to_i <=> x[:created_on].to_i } + elsif sortstr == "updated_at" + tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_at].to_i <=> x[:updated_at].to_i } + elsif sortstr == "updated_on" + tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_on].to_i <=> x[:updated_on].to_i } + end + + tmpIndex = 0 + for i in tStart..tEnd + tmpTopics[i] = tmpTopics_1[tmpIndex] + tmpIndex = tmpIndex + 1 + end + end + tStart = -1 + tEnd = -1 + tmpTopics_1 = [] + tmpIndex = 0 + end + end + end + end + return tmpTopics +end + +#按人气排序的时候 相同的人气必须按某种时间顺序排序 无置顶属性 +def sortby_time_countcommon_nosticky topics,sortstr + tmpTopics = [] + tmpTopics = topics + tStart = -1 + tEnd = -1 + + tmpTopics_1 = [] + tmpIndex = 0 + + tmpTopics.each_with_index do |topic,index| + if tStart == -1 + if (index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount]) + tStart = index + end + else + if ((topic[:infocount] == tmpTopics[index-1][:infocount]) && ((index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount]))) + tEnd = index + else + if (topic[:infocount] == tmpTopics[index-1][:infocount]) + tEnd = index + end + if tEnd > tStart + for i in tStart..tEnd + tmpTopics_1[tmpIndex] = tmpTopics[i] + tmpIndex = tmpIndex + 1 + end + + if sortstr == "created_at" + tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_at].to_i <=> x[:created_at].to_i } + elsif sortstr == "created_on" + tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_on].to_i <=> x[:created_on].to_i } + elsif sortstr == "updated_at" + tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_at].to_i <=> x[:updated_at].to_i } + elsif sortstr == "updated_on" + tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_on].to_i <=> x[:updated_on].to_i } + end + + tmpIndex = 0 + for i in tStart..tEnd + tmpTopics[i] = tmpTopics_1[tmpIndex] + tmpIndex = tmpIndex + 1 + end + end + tStart = -1 + tEnd = -1 + tmpTopics_1 = [] + tmpIndex = 0 + end + end + end + return tmpTopics +end + def strip_html(text,len=0,endss="...") ss = "" if text.length>0 ss=text.gsub(/<\/?.*?>/, '').strip + ss = ss.gsub(/ /, ' ') if len > 0 && ss.length > len ss = ss[0, len] + endss @@ -3076,3 +3273,13 @@ def strip_html(text,len=0,endss="...") return ss end +def get_hw_index(hw,is_teacher) + if is_teacher + homeworks = hw.course.homework_commons.order("created_at asc") + else + homeworks = hw.course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at asc") + end + hw_ids = homeworks.map{|hw| hw.id} if !homeworks.empty? + index = hw_ids.index(hw.id) + return index +end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 3a6b347b3..c10652c6f 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -850,7 +850,7 @@ module CoursesHelper # 学生按作业总分排序,取前8个 def hero_homework_score(course, score_sort_by) sql_select = "SELECT members.*,( - SELECT SUM(IF(student_works.final_score IS NULL,NULL,IF(student_works.final_score =0,0,IF((student_works.final_score - student_works.absence_penalty - student_works.late_penalty) < 0 , 0, student_works.final_score - student_works.absence_penalty - student_works.late_penalty)))) + SELECT SUM(work_score) FROM student_works,homework_commons WHERE student_works.homework_common_id = homework_commons.id AND homework_commons.course_id = #{course.id} diff --git a/app/helpers/organizations_helper.rb b/app/helpers/organizations_helper.rb index 4faa802a5..cba4fa210 100644 --- a/app/helpers/organizations_helper.rb +++ b/app/helpers/organizations_helper.rb @@ -63,14 +63,128 @@ module OrganizationsHelper def subfield_status_option type = [] option1 = [] - option1 << "列表" + option1 << "左一" option1 << "1" type << option1 - option2 = [] - option2 << "图片" - option2 << "0" - type << option2 + # option2 = [] + # option2 << "中一" + # option2 << "2" + # type << option2 + option3 = [] + option3 << "左二" + option3 << "3" + type << option3 + option4 = [] + option4 << "左三" + option4 << "4" + type << option4 + option5 = [] + option5 << "左四" + option5 << "5" + type << option5 + option6 = [] + option6 << "右一" + option6 << "6" + type << option6 + option7 = [] + option7 << "右二" + option7 << "7" + type << option7 + option8 = [] + option8 << "右三" + option8 << "8" + type << option8 type end + # 课程和项目不参与某些模块的排列 + def subfield_status_option_default + type = [] + option1 = [] + option1 << "左一" + option1 << "1" + type << option1 + option3 = [] + option3 << "左二" + option3 << "3" + type << option3 + option4 = [] + option4 << "左三" + option4 << "4" + type << option4 + option6 = [] + option6 << "右一" + option6 << "6" + type << option6 + type + end + + def subfield_list_type subfield + case subfield.to_i + when 1 + resulet = "左一" + when 2 + resulet = "左二" + when 3 + resulet = "左二" + when 4 + resulet = "左三" + when 5 + resulet = "左四" + when 6 + resulet = "右一" + when 7 + resulet = "右二" + when 8 + resulet = "右三" + end + end + + + def get_subfield_acts field + org_subfield = OrgSubfield.find(field.id) + org_subfield_ids = org_subfield.org_document_comments.map(&:id) << 0 + org_acts = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{org_subfield.id})").order('updated_at desc') + org_acts + end + + def org_subfield_had_created?(org, type) + sub_field = org.org_subfields.select{|subfield| subfield.field_type == type} + result = sub_field.length > 0 ? true : false + result + end + + def org_subfield_type(field) + case field.field_type + when "Post" + result = "帖子" + when "Resource" + result = "资源" + when "Compstu" + result = "学生" + when "Comptec" + result = "教师" + when "Complex" + result = "综合" + end + end + + def org_teacher_resource_count user + results = Attachment.find_by_sql("SELECT * FROM attachments where author_id = #{user.id};").count + end + + def org_teacher_course_count user + results = Course.find_by_sql("select * from courses where courses.tea_id = #{user.id}").count + end + + def org_student_course_count user + course_ids = user.courses.map { |c| c.is_delete == 0 && c.id} + results = Member.find_by_sql("select id from courses where courses.tea_id = #{user.id}").count + end + + def excellent_teachers + User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count + from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 and u.excellent_teacher =1 order by course_count desc").first(5) + end + end diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 36187b460..3cf781f76 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -41,6 +41,23 @@ module RepositoriesHelper identifiers.include?(iden) ? false :true end + # 获取文件目录的最新动态 + def get_trees_last_changes(project_id, rev, ent_name) + g = Gitlab.client + begin + tree_changes = g.rep_last_changes(project_id, :rev => rev, :path => ent_name) + tree_changes + rescue + logger.error("faile to get tress activities!") + end + end + + def translate_time time + case time + when time.include("") + end + end + # 获取diff内容行号 def diff_line_num content content.scan(/@@ -(\d+),\d+ \+\d+,\d+ @@/).first.join("").to_i diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index 4e11e153e..74788751b 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -23,7 +23,7 @@ module StudentWorkHelper #获取指定用户对某一作业的评分结果 def student_work_score work,user - StudentWorksScore.where(:user_id => user.id,:student_work_id => work.id).first + StudentWorksScore.where(:user_id => user.id,:student_work_id => work.id).last end #获取指定评分的角色 diff --git a/app/helpers/sub_document_comments_helper.rb b/app/helpers/sub_document_comments_helper.rb new file mode 100644 index 000000000..c1f2a4de1 --- /dev/null +++ b/app/helpers/sub_document_comments_helper.rb @@ -0,0 +1,2 @@ +module SubDocumentCommentsHelper +end diff --git a/app/helpers/sub_domains_helper.rb b/app/helpers/sub_domains_helper.rb new file mode 100644 index 000000000..ee1c18e71 --- /dev/null +++ b/app/helpers/sub_domains_helper.rb @@ -0,0 +1,5 @@ +module SubDomainsHelper + include OrganizationsHelper + + +end diff --git a/app/models/apply_homework.rb b/app/models/apply_homework.rb new file mode 100644 index 000000000..f4ded9733 --- /dev/null +++ b/app/models/apply_homework.rb @@ -0,0 +1,6 @@ +class ApplyHomework < ActiveRecord::Base + #status:1. 等待回复 2.审核通过 3.已拒绝 + belongs_to :user + belongs_to :homework_common + attr_accessible :status, :user_id, :homework_common_id +end diff --git a/app/models/apply_resource.rb b/app/models/apply_resource.rb new file mode 100644 index 000000000..df646166c --- /dev/null +++ b/app/models/apply_resource.rb @@ -0,0 +1,19 @@ +class ApplyResource < ActiveRecord::Base + # status:1. 等待回复 2.审核通过 3.已拒绝 + attr_accessible :attachment_id, :status, :user_id, :container_type, :container_id, :apply_user_id, :content + belongs_to :user + belongs_to :attachment + has_many :course_messages, :class_name => 'CourseMessage', :as => :course_message, :dependent => :destroy + after_create :act_as_apply_resource_message + + def act_as_apply_resource_message + self.course_messages << CourseMessage.new(:user_id => self.apply_user_id, :course_id => -1, :viewed => false, :status => 0, ) + # REDO:发送邮件 + # Mailer.run.apply_for_resource_request(self.container_id, User.current) + end + + def find_attachment attachment_id + Attachment.find(attachment_id) + end + +end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 754bd4dee..8f9ee2d85 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -35,6 +35,7 @@ class Attachment < ActiveRecord::Base # end include UserScoreHelper has_many :attachment_histories + has_many :apply_resources, :dependent => :destroy validates :filename, presence: true, length: {maximum: 254} validates :author, presence: true @@ -139,6 +140,12 @@ class Attachment < ActiveRecord::Base } ) end + + def get_apply_resource_status attachment_id, author_id + status = ApplyResource.where("attachment_id =? and user_id =?", attachment_id, author_id).first.try(:status) + status == 2 ? true :false + end + # add by nwb # 公开的项目id列表 def self.public_project_id @@ -301,7 +308,7 @@ class Attachment < ActiveRecord::Base nil end - def filename=(arg) + def filename=(arg) write_attribute :filename, sanitize_filename(arg.to_s) filename end @@ -536,6 +543,11 @@ class Attachment < ActiveRecord::Base end end + # 获取资源申请状态 + def get_status_by_attach user_id + ApplyResource.where("user_id =? and attachment_id =?", user_id, self.id).first.try(:status) + end + private # Physically deletes the file from the file system diff --git a/app/models/comment.rb b/app/models/comment.rb index 341a179ce..8632c243a 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -45,7 +45,8 @@ class Comment < ActiveRecord::Base if self.commented.course if self.author_id != self.commented.author_id self.course_messages << CourseMessage.new(:user_id => self.commented.author_id, :course_id => self.commented.course.id, :viewed => false) - if ShieldWechatMessage.where("container_type='User' and container_id=#{self.commented.author_id} and shield_type='Course' and shield_id=#{self.commented.course.id}").count == 0 + count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.commented.author_id} and shield_type='Course' and shield_id=#{self.commented.course.id}").count + if count == 0 content = strip_html self.comments.html_safe, 200 ws.comment_template self.commented.author_id, "course_notice", self.id, "#{l(:label_notice_comment_template)}", self.author.try(:realname), format_time(self.created_on), content end diff --git a/app/models/course_activity.rb b/app/models/course_activity.rb index 96ec6e355..2aae45d0a 100644 --- a/app/models/course_activity.rb +++ b/app/models/course_activity.rb @@ -5,8 +5,7 @@ class CourseActivity < ActiveRecord::Base belongs_to :course belongs_to :user has_many :user_acts, :class_name => 'UserAcivity',:as =>:act - after_save :add_user_activity, :add_org_activity - after_create :add_course_lead + after_create :add_course_lead,:add_user_activity, :add_org_activity before_destroy :destroy_user_activity, :destroy_org_activity #在个人动态里面增加当前动态 diff --git a/app/models/course_message.rb b/app/models/course_message.rb index 79d27f3c5..59fcfe456 100644 --- a/app/models/course_message.rb +++ b/app/models/course_message.rb @@ -1,8 +1,11 @@ class CourseMessage < ActiveRecord::Base # status说明: status在课程不同的类型,区分不同的功能 status = 9 作品的提交记录 + # ApplyResource status: + # 0: 发送申请 1:回复允许申请 2:拒绝申请消息 # HomeworkCommon:status: - # nil:发布了作业; 1:作业截止时间到了提醒!;2:开启匿评; 3:关闭匿评; 4:匿评开始失败 - attr_accessible :course_id, :course_message_id, :course_message_type, :user_id, :viewed, :content, :status + # nil:发布了作业; 1:作业截止时间到了提醒!;2:开启匿评; 3:关闭匿评; 4:匿评开始失败; 5:申请引用作业, 6:申请结果 + # apply_user_id: 申请者的用户id + attr_accessible :course_id, :course_message_id, :course_message_type, :user_id, :viewed, :content, :status, :apply_user_id, :apply_result # 多态 虚拟关联 belongs_to :course_message ,:polymorphic => true @@ -14,7 +17,7 @@ class CourseMessage < ActiveRecord::Base validates :course_id,presence: true validates :course_message_id,presence: true validates :course_message_type, presence: true - validates_length_of :content, :maximum => 100 + #validates_length_of :content, :maximum => 100 after_create :add_user_message def add_user_message diff --git a/app/models/forge_activity.rb b/app/models/forge_activity.rb index c044392a0..44b13b315 100644 --- a/app/models/forge_activity.rb +++ b/app/models/forge_activity.rb @@ -20,7 +20,7 @@ class ForgeActivity < ActiveRecord::Base validates :forge_act_id,presence: true validates :forge_act_type, presence: true has_many :user_acts, :class_name => 'UserAcivity',:as =>:act - after_save :add_user_activity, :add_org_activity + after_create :add_user_activity, :add_org_activity before_destroy :destroy_user_activity, :destroy_org_activity #在个人动态里面增加当前动态 diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index b47008393..e4426e78f 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -18,6 +18,7 @@ class HomeworkCommon < ActiveRecord::Base has_many :student_works, :dependent => :destroy, :conditions => "is_test=0" has_many :student_works_evaluation_distributions, :through => :student_works #一个作业的分配的匿评列表 has_many :journals_for_messages, :as => :jour, :dependent => :destroy + has_many :apply_homeworks, :dependent => :destroy has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy #用户活动 # 课程动态 has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy @@ -28,7 +29,7 @@ class HomeworkCommon < ActiveRecord::Base :description => :description, :author => :author, :url => Proc.new {|o| {:controller => 'student_work', :action => 'index', :homework => o.id}} - after_create :act_as_activity, :send_mail, :act_as_course_message + after_create :act_as_activity, :send_mail,:act_as_course_message after_update :update_activity, :wechat_message after_save :act_as_course_activity after_destroy :delete_kindeditor_assets @@ -58,8 +59,9 @@ class HomeworkCommon < ActiveRecord::Base else self.course.members.each do |m| # if m.user_id != self.user_id - self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) - if ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count == 0 + #self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) + count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count + if count == 0 ws = WechatService.new ws.homework_template(m.user_id, "homework", self.id, "#{l(:label_new_homework_template)}", self.course.name, self.name.html_safe, self.end_time.to_s + " 23:59:59") end @@ -108,7 +110,8 @@ class HomeworkCommon < ActiveRecord::Base #修改作业后发送微信模板消息 def wechat_message self.course.members.each do |member| - if ShieldWechatMessage.where("container_type='User' and container_id=#{member.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count == 0 + count = ShieldWechatMessage.where("container_type='User' and container_id=#{member.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count + if count == 0 ws = WechatService.new ws.homework_template(member.user_id, "homework", self.id, "#{l(:label_update_homework_template)}", self.course.name, self.name.html_safe, self.end_time.to_s + " 23:59:59") end diff --git a/app/models/issue.rb b/app/models/issue.rb index 6e3dcc57a..b5e87feea 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -162,9 +162,22 @@ class Issue < ActiveRecord::Base end self.project.members.each do |m| count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Project' and shield_id=#{self.project_id}").count - if m.user_id != self.author_id && count != 0 + if m.user_id != self.author_id && count == 0 ws = WechatService.new - content = strip_html self.project.name + " 有新缺陷了:" + self.subject.html_safe, 200 + str = " 有新缺陷了: " + case self.tracker_id + when 1 + str = " 有新缺陷了: " + when 2 + str = " 有新功能了: " + when 3 + str = " 有新支持了: " + when 4 + str = " 有新任务了: " + when 5 + str = " 有新周报了: " + end + content = strip_html self.project.name + str + self.subject.html_safe, 200 ws.message_update_template m.user_id, "issues", self.id, "#{l(:label_new_issue_template)}", content, format_time(self.created_on) end end @@ -262,7 +275,7 @@ class Issue < ActiveRecord::Base # set default values for new records only self.status ||= IssueStatus.default self.priority ||= IssuePriority.default - self.watcher_user_ids = [] + # self.watcher_user_ids = [] end end diff --git a/app/models/journal.rb b/app/models/journal.rb index 02086fa62..eeaa17dd6 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -239,8 +239,10 @@ class Journal < ActiveRecord::Base #缺陷回复微信模板消息 def issue_wechat_message - ws = WechatService.new - content = strip_html self.notes.html_safe, 200 - ws.comment_template self.issue.author_id, "issues", self.journalized_id, "#{l(:label_issue_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + if !self.notes.nil? && self.notes.gsub(' ','') != '' + ws = WechatService.new + content = strip_html self.notes.html_safe, 200 + ws.comment_template self.issue.author_id, "issues", self.journalized_id, "#{l(:label_issue_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + end end end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 675c07b06..d0113744c 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -255,11 +255,30 @@ class JournalsForMessage < ActiveRecord::Base self.course_messages << CourseMessage.new(:user_id => r, :course_id => self.jour.id, :viewed => false) end end - if self.jour_type == 'HomeworkCommon' && ShieldWechatMessage.where("container_type='User' and container_id=#{self.jour.user_id} and shield_type='Course' and shield_id=#{self.jour.course_id}").count == 0 - ws = WechatService.new - #content = truncate(strip_tags(self.notes.to_s), length: 200) - content = strip_html self.notes.html_safe, 200 - ws.comment_template self.jour.user_id, "homework", self.jour_id, "#{l(:label_homework_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + if self.jour_type == 'HomeworkCommon' + if self.m_parent_id.nil? + if self.user_id != self.jour.user_id + self.course_messages << CourseMessage.new(:user_id => self.jour.user_id,:course_id => self.jour.course.id, :viewed => false) + count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.jour.user_id} and shield_type='Course' and shield_id=#{self.jour.course_id}").count + if count == 0 + ws = WechatService.new + #content = truncate(strip_tags(self.notes.to_s), length: 200) + content = strip_html self.notes.html_safe, 200 + ws.comment_template self.jour.user_id, "homework", self.jour_id, "#{l(:label_homework_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + end + end + else + if self.user_id != self.parent.user_id + self.course_messages << CourseMessage.new(:user_id => self.parent.user_id,:course_id => self.jour.course.id, :viewed => false) + count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.parent.user_id} and shield_type='Course' and shield_id=#{self.jour.course_id}").count + if count == 0 + ws = WechatService.new + #content = truncate(strip_tags(self.notes.to_s), length: 200) + content = strip_html self.notes.html_safe, 200 + ws.comment_template self.parent.user_id, "homework", self.jour_id, "#{l(:label_new_second_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + end + end + end end end diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 664e5cfac..8d8fa7085 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -1041,7 +1041,13 @@ class Mailer < ActionMailer::Base :subject => @subject end - + def apply_for_homework_request(homework, user) + @receive = User.find(homework.user_id) + @user = user + @subject = "#{@user.show_name} #{l(:label_apply_for_homework)} #{homework.name} " + mail :to => @receive.mail, + :subject => @subject + end private diff --git a/app/models/member.rb b/app/models/member.rb index cc227cf31..3cb70a8fe 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -150,7 +150,7 @@ class Member < ActiveRecord::Base #当前学生在指定作业内的得分 def homework_common_score homework_common - StudentWork.select("IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as final_score").where(:homework_common_id => homework_common.id,:user_id => self.user_id) + StudentWork.select("work_score").where(:homework_common_id => homework_common.id,:user_id => self.user_id) end def student_work_score_avg @@ -158,7 +158,7 @@ class Member < ActiveRecord::Base end def student_work_score_sum - sql_select = "SELECT (SUM(IF(student_works.final_score IS NULL,NULL,IF(student_works.final_score =0,0,IF((student_works.final_score - student_works.absence_penalty - student_works.late_penalty) < 0 , 0, student_works.final_score - student_works.absence_penalty - student_works.late_penalty))))) AS score + sql_select = "SELECT (SUM(student_works.work_score)) AS score FROM student_works,homework_commons WHERE student_works.homework_common_id = homework_commons.id AND homework_commons.course_id = #{self.course_id} diff --git a/app/models/message.rb b/app/models/message.rb index eece8ef81..fdc3c6bdc 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -83,7 +83,7 @@ class Message < ActiveRecord::Base # after_create :add_author_as_watcher, :reset_counters!, :add_boards_count after_update :update_messages_board, :update_activity after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets, :decrease_boards_count, :down_course_score - after_create :act_as_course_activity, :act_as_forge_activity, :act_as_student_score, act_as_at_message(:content, :author_id), :add_author_as_watcher, :reset_counters!, :add_boards_count + after_create :act_as_course_activity, :act_as_forge_activity, :act_as_student_score, act_as_at_message(:content, :author_id), :add_author_as_watcher, :reset_counters!, :add_boards_count, :act_as_system_message #before_save :be_user_score scope :visible, lambda {|*args| @@ -261,10 +261,11 @@ class Message < ActiveRecord::Base ws = WechatService.new if self.course if self.parent_id.nil? # 主贴 - self.course.members.each do |m| + self.course.members.includes(:user).each do |m| if self.author.allowed_to?(:as_teacher, self.course) && m.user_id != self.author_id # 老师 自己的帖子不给自己发送消息 - self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false) - if ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course.id}").count == 0 + #self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false) + count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course.id}").count + if count == 0 content = strip_html self.subject, 200 ws.topic_publish_template m.user_id, "course_discussion", self.id, "#{l(:label_course_topic_template)}", content, self.author.try(:realname), format_time(self.created_on) end @@ -274,7 +275,8 @@ class Message < ActiveRecord::Base parent_author_id = Message.find(self.parent_id).author_id if parent_author_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 self.course_messages << CourseMessage.new(:user_id => parent_author_id, :course_id => self.board.course_id, :viewed => false) - if ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Course' and shield_id=#{self.board.course_id}").count == 0 + count = ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Course' and shield_id=#{self.board.course_id}").count + if count == 0 content = strip_html self.content.html_safe, 200 ws.comment_template parent_author_id, "course_discussion", self.parent_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content end @@ -282,10 +284,11 @@ class Message < ActiveRecord::Base end elsif self.project # 项目相关 if self.parent_id.nil? # 主贴 - self.project.members.each do |m| + self.project.members.includes(:user).each do |m| if m.user_id != self.author_id - self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false) - if ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Project' and shield_id=#{self.project.id}").count == 0 + #self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false) + count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Project' and shield_id=#{self.project.id}").count + if count == 0 content = strip_html self.subject, 200 ws.topic_publish_template m.user_id, "project_discussion", self.id, "#{l(:label_project_topic_template)}", content, self.author.try(:realname), format_time(self.created_on) end @@ -295,7 +298,8 @@ class Message < ActiveRecord::Base parent_author_id = Message.find(self.parent_id).author_id if parent_author_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 self.forge_messages << ForgeMessage.new(:user_id => parent_author_id, :project_id => self.board.project_id, :viewed => false) - if ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Project' and shield_id=#{self.board.project_id}").count == 0 + count = ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Project' and shield_id=#{self.board.project_id}").count + if count == 0 content = strip_html self.content.html_safe, 200 ws.comment_template parent_author_id, "project_discussion", self.parent_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content end diff --git a/app/models/news.rb b/app/models/news.rb index cd16442a0..877d799bf 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -62,7 +62,7 @@ class News < ActiveRecord::Base :author_key => :author_id acts_as_watchable - after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity,:act_as_system_message, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score + after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score, :act_as_system_message after_update :update_activity after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities, :down_course_score @@ -163,17 +163,18 @@ class News < ActiveRecord::Base end end - #课程/项目通知 消息发送 - #消息发送原则:除了消息的发布者,课程的其它成员都能收到消息提醒 + # 课程/项目通知 消息发送 + # 消息发送原则:除了消息的发布者,课程的其它成员都能收到消息提醒 def act_as_system_message if self.course self.course.members.each do |m| if m.user_id != self.author_id - self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) - if ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count == 0 + # self.delay.send_message(m.user_id, self.course_id) + count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count + if count == 0 ws = WechatService.new content = strip_html self.author.try(:realname) + " 发布了通知:" + self.title.html_safe, 200 - ws.message_update_template m.user_id, "course_notice", self.id, "#{l(:label_new_notice_template)}", self.author.try(:realname) + " 发布了通知:" + content, format_time(self.created_on) + ws.message_update_template m.user_id, "course_notice", self.id, "#{l(:label_new_notice_template)}", content, format_time(self.created_on) end end end @@ -188,6 +189,10 @@ class News < ActiveRecord::Base end end + # def send_message user_id, course_id + # self.course_messages << CourseMessage.new(:user_id => user_id, :course_id => course_id, :viewed => false) + # end + # Time 2015-03-31 13:50:54 # Author lizanle # Description 删除news后删除对应的资源 diff --git a/app/models/org_subfield.rb b/app/models/org_subfield.rb index 8cec49686..1151426e3 100644 --- a/app/models/org_subfield.rb +++ b/app/models/org_subfield.rb @@ -7,6 +7,7 @@ class OrgSubfield < ActiveRecord::Base has_many :messages, :through => :org_subfield_messages has_many :boards, :dependent => :destroy has_many :news, :dependent => :destroy + has_many :sub_domains, :dependent => :destroy acts_as_attachable after_create :create_board_sync after_destroy :update_priority diff --git a/app/models/organization.rb b/app/models/organization.rb index 427cd4c10..c35d0591d 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -22,4 +22,16 @@ class Organization < ActiveRecord::Base OrgSubfield.create(:organization_id => self.id, :name => 'course', :field_type => 'default', :priority => 2) OrgSubfield.create(:organization_id => self.id, :name => 'project', :field_type => 'default', :priority => 3) end + + def switch_type + self.show_mode.to_i == 1 ? true : false + end + + def allow_set_teachers + self.allow_teacher.to_i == 1 ? true : false + end + + def secdomain_name + Secdomain.where("sub_type=2 and pid=?", self.id).first.try(:subname) + end end diff --git a/app/models/praise_tread.rb b/app/models/praise_tread.rb index b1b7e0908..63ba89b18 100644 --- a/app/models/praise_tread.rb +++ b/app/models/praise_tread.rb @@ -88,4 +88,11 @@ class PraiseTread < ActiveRecord::Base UserLevels.update_user_level(target_user) end end + + def self.praised(activity) + self.where(praise_tread_object_id: activity.id, + praise_tread_object_type: activity.class.to_s, + user_id: User.current.id).empty? + end + end diff --git a/app/models/repository.rb b/app/models/repository.rb index 571bba1b9..305c82f97 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -44,7 +44,7 @@ class Repository < ActiveRecord::Base # validates_uniqueness_of :identifier, :allow_blank => true validates_exclusion_of :identifier, :in => %w(show entry raw changes annotate diff show stats graph) # donwcase letters, digits, dashes, underscores but not digits only - validates_format_of :identifier, :with => /^[a-z0-9_\-]+$/, :allow_blank => true + validates_format_of :identifier, :with => /^[a-zA-Z0-9_\-]*[a-zA-Z_\-]+[a-zA-Z0-9_\-]*$/, :allow_blank => true # Checks if the SCM is enabled when creating a repository validate :repo_create_validation, :on => :create diff --git a/app/models/school.rb b/app/models/school.rb index 6cafb0473..b9a1d88cb 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -5,4 +5,5 @@ class School < ActiveRecord::Base def to_s self.name.to_s end + end diff --git a/app/models/sso.rb b/app/models/sso.rb new file mode 100644 index 000000000..c987ff933 --- /dev/null +++ b/app/models/sso.rb @@ -0,0 +1,60 @@ +#coding=utf-8 + +require 'base64' + +class Sso < ActiveRecord::Base + belongs_to :user + attr_accessible :email, :name, :openid, :password, :school, :sex, :user, :user_id + + validates :user_id, :user, :email, :openid, :presence => true + + def self.sync_user(opt) + sso = Sso.where(openid: opt["openid"]).first + return sso if sso + + sso = Sso.new + sso.name = opt["name"] + sso.openid = opt["openid"] + sso.email = opt["email"] + sso.password = opt["password"] + sso.school = opt["school"] + sso.sex = opt["sex"] + + + # 查邮箱 + user = User.where(mail: opt["email"]).first + + unless user + # 查用户名 + + user = User.where(login: opt["name"]).first + if user + # 跳到修改用户名 + raise "exist user" + end + + password = opt["password"] + if password.size < 8 + password = random_pwd + end + us = UsersService.new + user = us.register(login: opt["name"], mail: opt["email"], + password: password, + :should_confirmation_password => false) + if user.new_record? + raise user.errors.full_messages.first + end + end + + sso.user = user + sso.save! + return sso + end + + + private + def self.random_pwd + ('a'..'z').to_a.shuffle[0..7].join + end + +end diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 82b1ad4a1..ddd91df38 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -50,6 +50,7 @@ class StudentWork < ActiveRecord::Base if homework.teacher_priority == 1 #教师优先 if student_work.teacher_score student_work.final_score = student_work.teacher_score + student_work.work_score = student_work.teacher_score else if student_work.teaching_asistant_score.nil? student_work.final_score = student_work.student_score @@ -62,9 +63,17 @@ class StudentWork < ActiveRecord::Base final_score = final_ta_score + final_s_score student_work.final_score = format("%.2f",final_score.to_f) end + if student_work.final_score + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + else + student_work.work_score = nil + end end else #不考虑教师评分 - if student_work.teaching_asistant_score.nil? + if student_work.student_score.nil? && student_work.teaching_asistant_score.nil? + student_work.final_score = student_work.teacher_score + elsif student_work.teaching_asistant_score.nil? student_work.final_score = student_work.student_score elsif student_work.student_score.nil? student_work.final_score = student_work.teaching_asistant_score @@ -75,11 +84,18 @@ class StudentWork < ActiveRecord::Base final_score = final_ta_score + final_s_score student_work.final_score = format("%.2f",final_score.to_f) end + if student_work.final_score + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + else + student_work.work_score = nil + end end elsif homework.homework_type == 2 && homework.homework_detail_programing #编程作业-----设定:系统评分必定不为空 if homework.teacher_priority == 1 #教师优先 if student_work.teacher_score student_work.final_score = student_work.teacher_score + student_work.work_score = student_work.teacher_score else if student_work.teaching_asistant_score.nil? #教辅未评分 if student_work.student_score.nil? @@ -108,7 +124,13 @@ class StudentWork < ActiveRecord::Base final_score = final_sy_score + final_ts_score + final_st_score student_work.final_score = format("%.2f",final_score.to_f) end - end + if student_work.final_score + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + else + student_work.work_score = nil + end + end else #不考虑教师评分 if student_work.teaching_asistant_score.nil? #教辅未评分 if student_work.student_score.nil? @@ -137,6 +159,12 @@ class StudentWork < ActiveRecord::Base final_score = final_sy_score + final_ts_score + final_st_score student_work.final_score = format("%.2f",final_score.to_f) end + if student_work.final_score + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + else + student_work.work_score = nil + end end end end diff --git a/app/models/student_works_score.rb b/app/models/student_works_score.rb index aa38c5dcd..b2fc4fdcd 100644 --- a/app/models/student_works_score.rb +++ b/app/models/student_works_score.rb @@ -18,17 +18,29 @@ class StudentWorksScore < ActiveRecord::Base receiver = self.student_work.user # 判断是第一次评阅还是更新 status:0 新建;1 更新 if self.created_at == self.updated_at - if self.comment.nil? + if self.comment.nil? && self.score self.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => self.student_work.homework_common.course.id, :viewed => false, :content => "作业评分:#{self.score}", :status=> false) + elsif self.score.nil? && self.comment + self.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => self.student_work.homework_common.course.id, + :viewed => false, :content => "评语:#{self.comment}", :status=> false) + elsif self.comment.nil? && self.score.nil? + self.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => self.student_work.homework_common.course.id, + :viewed => false, :content => "上传了批阅附件", :status=> false) else self.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => self.student_work.homework_common.course.id, :viewed => false, :content => "作业评分:#{self.score} 评语:#{self.comment}", :status=> false) end else # 更新 - if self.comment.nil? + if self.comment.nil? && self.score self.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => self.student_work.homework_common.course.id, :viewed => false, :content => "作业评分:#{self.score}", :status=> true) + elsif self.score.nil? && self.comment + self.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => self.student_work.homework_common.course.id, + :viewed => false, :content => "评语:#{self.comment}", :status=> true) + elsif self.comment.nil? && self.score.nil? + self.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => self.student_work.homework_common.course.id, + :viewed => false, :content => "上传了批阅附件", :status=> true) else self.course_messages << CourseMessage.new(:user_id => receiver.id, :course_id => self.student_work.homework_common.course.id, :viewed => false, :content => "作业评分:#{self.score} 评语:#{self.comment}", :status=> true) diff --git a/app/models/sub_document_comment.rb b/app/models/sub_document_comment.rb new file mode 100644 index 000000000..799fed7ce --- /dev/null +++ b/app/models/sub_document_comment.rb @@ -0,0 +1,33 @@ +class SubDocumentComment < ActiveRecord::Base + attr_accessible :content, :creator_id, :locked, :org_subfield_id, :parent_id, :reply_id, :sticky, :sub_domain_id, :title + + include Redmine::SafeAttributes + include ApplicationHelper + belongs_to :sub_domain + belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id' + acts_as_tree :order => "#{SubDocumentComment.table_name}.sticky asc, #{SubDocumentComment.table_name}.created_at desc" + acts_as_attachable + has_many :org_acts, :class_name => 'OrgActivity',:as =>:org_act ,:dependent => :destroy + after_create :document_save_as_sub_activity + after_update :update_activity + validates_presence_of :content + + #动态的更新 + private + def update_activity + org_activity = OrgActivity.where("org_act_type='SubDocumentComment' and org_act_id =?", id).first + if org_activity + org_activity.updated_at = Time.now + org_activity.save + end + end + + def document_save_as_sub_activity + if(self.parent().nil?) + self.org_acts << OrgActivity.new(:user_id => User.current.id, :container_id => self.sub_domain.id, :container_type => 'SubDomain') + else + act = OrgActivity.where("org_act_type='SubDocumentComment' and org_act_id =?", self.root.id).first + act.update_attributes(:updated_at => self.updated_at) + end + end +end diff --git a/app/models/sub_domain.rb b/app/models/sub_domain.rb new file mode 100644 index 000000000..0ae325e1a --- /dev/null +++ b/app/models/sub_domain.rb @@ -0,0 +1,5 @@ +class SubDomain < ActiveRecord::Base + attr_accessible :field_type, :hide, :name, :org_subfield_id, :priority, :status + belongs_to :org_subfield, :foreign_key => :org_subfield_id + has_many :sub_document_comments, :dependent => :destroy +end diff --git a/app/models/user.rb b/app/models/user.rb index dc7a3e741..44ef54c95 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -108,6 +108,8 @@ class User < Principal has_many :student_works_evaluation_distributions, :dependent => :destroy has_many :student_works_scores, :dependent => :destroy has_many :student_work_projects, :dependent => :destroy + has_many :apply_homeworks, :dependent => :destroy + has_many :apply_resources, :dependent => :destroy #end has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)}, @@ -181,6 +183,8 @@ class User < Principal has_one :user_wechat + has_one :sso + # add by zjc has_one :level, :class_name => 'UserLevels', :dependent => :destroy has_many :memos , :foreign_key => 'author_id' @@ -306,6 +310,20 @@ class User < Principal end # ====================================================================== + def my_workplace + self.user_extensions.try(:occupation).to_s + end + + def my_blogs_count + self.blog.blog_comments.where("#{BlogComment.table_name}.parent_id is null").count + end + + def my_students + my_students=StudentsForCourse.find_by_sql("SELECT SUM(student_count) as students_count, c.tea_id FROM courses c, (SELECT course_id , COUNT(id) AS student_count FROM students_for_courses GROUP BY course_id) AS ct + WHERE c.id= ct.course_id and c.tea_id = #{self.id} GROUP BY c.tea_id").first + results = my_students.blank? ? 0 : my_students.students_count + results + end # 查询用户未读过的记录 # 用户留言记录 @@ -1070,16 +1088,22 @@ class User < Principal anonymous_user end + def self.is_id?(id) + Fixnum===id || id.to_i.to_s == id + end + # refactor User model find function, # return anonymous user when can not find user id = user_id def self.find (*args, &block) begin + return find_by_login(args.first) if args.size==1 && !is_id?(args.first) super rescue self.anonymous end # super end + # Salts all existing unsalted passwords # It changes password storage scheme from SHA1(password) to SHA1(salt + SHA1(password)) # This method is used in the SaltPasswords migration and is to be kept as is diff --git a/app/services/wechat_service.rb b/app/services/wechat_service.rb index 1abf5e888..6d8c0f234 100644 --- a/app/services/wechat_service.rb +++ b/app/services/wechat_service.rb @@ -1,11 +1,11 @@ #encoding: utf-8 class WechatService - def template_data(openid, template_id, type, id, first, key1, key2, key3, remark="具体内容请点击详情查看网站") + def template_data(openid, template_id, type, id, first, key1, key2, key3, remark="") data = { touser:openid, template_id:template_id, - url:"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect", + url:"https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{Setting.protocol}://#{Setting.host_name}/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect", topcolor:"#FF0000", data:{ first: { @@ -33,7 +33,7 @@ class WechatService data end - def homework_template(user_id, type, id, first, key1, key2, key3, remark="具体内容请点击详情查看网站") + def homework_template(user_id, type, id, first, key1, key2, key3, remark="") uw = UserWechat.where(user_id: user_id).first unless uw.nil? data = template_data uw.openid,"3e5Dj2GIx8MOcMyRKpTUEQnM7Tg0ASSCNc01NS9HCGI", type, id, first, key1, key2, key3, remark @@ -44,10 +44,9 @@ class WechatService end Rails.logger.info "send over. #{req}" end - Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect" end - def topic_publish_template(user_id, type, id, first, key1, key2, key3, remark="具体内容请点击详情查看网站") + def topic_publish_template(user_id, type, id, first, key1, key2, key3, remark="") uw = UserWechat.where(user_id: user_id).first unless uw.nil? data = template_data uw.openid,"oKzFCdk7bsIHnGbscA__N8LPQrBkUShvpjV3-kuwWDQ", type, id,first, key1, key2, key3, remark @@ -59,10 +58,9 @@ class WechatService end Rails.logger.info "send over. #{req}" end - Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect" end - def comment_template(user_id,type, id, first, key1, key2, key3, remark="具体内容请点击详情查看网站") + def comment_template(user_id,type, id, first, key1, key2, key3, remark="") uw = UserWechat.where(user_id: user_id).first unless uw.nil? data = template_data uw.openid,"A_3f5v90-zK73V9Kijm-paDkl9S-NuM8Cf-1UJi92_c",type, id,first, key1, key2, key3, remark @@ -74,16 +72,15 @@ class WechatService end Rails.logger.info "send over. #{req}" end - Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect" end - def message_update_template(user_id, type, id, first, key1, key2, remark="具体内容请点击详情查看网站") + def message_update_template(user_id, type, id, first, key1, key2, remark="") uw = UserWechat.where(user_id: user_id).first unless uw.nil? data = { touser:uw.openid, template_id:"YTyNPZnQD8uZFBFq-Q6cCOWaq5LA9vL6RFlF2JuD5Cg", - url:"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect", + url:"https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{Setting.protocol}://#{Setting.host_name}/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect", topcolor:"#FF0000", data:{ first: { @@ -112,6 +109,5 @@ class WechatService end Rails.logger.info "send over. #{req}" end - Rails.logger.info "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://www.trustie.net/assets/wechat/app.html#/#{type}/#{id}?response_type=code&scope=snsapi_base&state=123#wechat_redirect" end end \ No newline at end of file diff --git a/app/views/admin/apply_for_homework.html.erb b/app/views/admin/apply_for_homework.html.erb new file mode 100644 index 000000000..25d15f707 --- /dev/null +++ b/app/views/admin/apply_for_homework.html.erb @@ -0,0 +1,89 @@ +
#{@org_comment.content.html_safe}
+ 序号 + | ++ 作业名称 + | ++ 课程名称 + | ++ 作者 + | ++ 申请者 + | ++ 申请状态 + | ++ 申请日期 + | +
---|---|---|---|---|---|---|
+ <%=@count %> + | + <% c_h = HomeworkCommon.find homework.homework_common_id %> + <% if c_h %> + + <% if c_h.course %> + + <% end %> + + <% end %> + ++ <% if homework.status == 1 %> + 等待回复 + <% elsif homework.status == 2 %> + 已通过 + <% else %> + 已拒绝 + <% end %> + | ++ <%=format_date( homework.created_at ) %> + | +
+ <%= count>0 ? "#{count}" :"0" %> + 回复 + | + <%= get_praise_num(activity) > 0 ? "#{get_praise_num(activity)}" :"0" %> + 赞 +
+<%= l(:label_no_data) %>
+ <% end %> +