diff --git a/Gemfile b/Gemfile index f3b06c2d4..da3b3b4d7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,11 +1,13 @@ source 'https://rubygems.org/' -### 这里执行bundle config mirror.https://rubygems.org https://gems.ruby-china.org 切换到ruby-china源 +### ����ִ��bundle config mirror.https://rubygems.org https://gems.ruby-china.org �л���ruby-chinaԴ unless RUBY_PLATFORM =~ /w32/ # unix-like only gem 'iconv' end +#gem 'certified' + gem 'wechat',path: 'lib/wechat' gem 'grack', path:'lib/grack' gem 'gitlab', path: 'lib/gitlab-cli' diff --git a/app/api/mobile/entities/blog_comment.rb b/app/api/mobile/entities/blog_comment.rb index b11194b30..67904d11e 100644 --- a/app/api/mobile/entities/blog_comment.rb +++ b/app/api/mobile/entities/blog_comment.rb @@ -47,6 +47,7 @@ module Mobile blog_comment_expose :created_at blog_comment_expose :lasted_comment blog_comment_expose :id + blog_comment_expose :locked blog_comment_expose :praise_count expose :blog_comment_children, using:Mobile::Entities::BlogComment do |c,opt| if c.is_a? (::BlogComment) diff --git a/app/api/mobile/entities/message.rb b/app/api/mobile/entities/message.rb index 912b07e62..051c92886 100644 --- a/app/api/mobile/entities/message.rb +++ b/app/api/mobile/entities/message.rb @@ -51,6 +51,7 @@ module Mobile message_expose :replies_count message_expose :praise_count message_expose :created_on + message_expose :locked message_expose :id message_expose :lasted_comment expose :message_children,using:Mobile::Entities::Message do |c,opt| diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 0fd4cc2c9..1478bceae 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -162,6 +162,7 @@ class CoursesController < ApplicationController @subPage_title = l :label_student_list @canShowCode = User.current.allowed_to?(:as_teacher,@course) && params[:role] != '1' # @is_remote = true + @sort_type = 'score' @score_sort_by = "desc" q = "#{params[:name].strip}" if params[:incourse] @@ -185,9 +186,11 @@ class CoursesController < ApplicationController group.course_id = @course.id group.save end + @sort_type = 'score' + @score_sort_by = "desc" @canShowCode = User.current.allowed_to?(:as_teacher,@course) && params[:role] != '1' @is_remote = true - @members = student_homework_score(0,0, 10,"desc") + @members = student_homework_score(0,0, 10,@score_sort_by) @course_groups = @course.course_groups end @@ -196,7 +199,9 @@ class CoursesController < ApplicationController @subPage_title = l :label_student_list @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @is_remote = true - + @sort_type = 'score' + @score_sort_by = "desc" + @members = student_homework_score(0,0, 10,@score_sort_by) @course_groups = @course.course_groups end @@ -281,6 +286,7 @@ class CoursesController < ApplicationController @render_file = 'new_member_list' @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @is_remote = true + @sort_type = 'score' @score_sort_by = "desc" if params[:group_id] && params[:group_id] != "0" @group = CourseGroup.find(params[:group_id]) @@ -298,6 +304,7 @@ class CoursesController < ApplicationController @render_file = 'new_member_list' @score_sort_by = "desc" + @sort_type = "score" @canShowCode = User.current.allowed_to?(:as_teacher,@course) && params[:role] != '1' @role = params[:role].nil? ? '2':params[:role] @is_remote = true @@ -312,7 +319,7 @@ class CoursesController < ApplicationController if @course.open_student == 1 || User.current.member_of_course?(@course) @subPage_title = l :label_student_list page = params[:page].nil? ? 0 : (params['page'].to_i - 1) - @all_members = student_homework_score(0,page, 10,"desc") + @all_members = student_homework_score(0,page, 10,@score_sort_by) @members = @all_members else render_403 @@ -350,28 +357,29 @@ class CoursesController < ApplicationController @subPage_title = l :label_student_list @render_file = 'new_member_list' @is_remote = true + @sort_type = params[:sort_type] if params[:sort_type] @score_sort_by = params[:sort_by] if params[:sort_by] @search_name = params[:search_name] if params[:search_name] group_id = params[:group_id] if !@search_name.nil? if group_id == '0' page = params[:page].nil? ? 0 : (params['page'].to_i - 1) - @results = searchmember_by_name(student_homework_score(0,0,0,@score_sort_by), @search_name) + @results = searchmember_by_name(student_homework_score(0,0,0,@score_sort_by,@sort_type), @search_name) @result_count = @results.count # @results = paginateHelper @results, 10 else @group = CourseGroup.find(group_id) - @results = searchmember_by_name(student_homework_score(group_id, 0, 0,@score_sort_by),@search_name) + @results = searchmember_by_name(student_homework_score(group_id, 0, 0,@score_sort_by,@sort_type),@search_name) @result_count = @results.count # @results = paginateHelper @results, 10 end else if group_id == '0' page = params[:page].nil? ? 0 : (params['page'].to_i - 1) - @results = student_homework_score(0,page, 10,@score_sort_by) + @results = student_homework_score(0,page, 10,@score_sort_by,@sort_type) else @group = CourseGroup.find(group_id) - @results = student_homework_score(group_id, 0, 0,@score_sort_by) + @results = student_homework_score(group_id, 0, 0,@score_sort_by,@sort_type) end end end @@ -384,6 +392,15 @@ class CoursesController < ApplicationController end end + # 显示每个学生的作业评分详情 + def show_member_act_score + @member = Member.find(params[:member_id]) if params[:member_id] + respond_to do |format| + format.html {render :layout => 'course_base'} + format.js + end + end + def handle_course courses, activities course_activity_count_array=activities.values() course_array=[] @@ -1149,7 +1166,7 @@ class CoursesController < ApplicationController end end - def student_homework_score(groupid,start_from, nums, score_sort_by) + def student_homework_score(groupid,start_from, nums, score_sort_by, sort_type = 'score') start_from = start_from * nums sql_select = "" if groupid == 0 @@ -1159,11 +1176,13 @@ class CoursesController < ApplicationController WHERE student_works.homework_common_id = homework_commons.id AND homework_commons.course_id = #{@course.id} AND student_works.user_id = members.user_id - ) AS score + ) AS score,(SELECT (message_num*2 + message_reply_num*1 + news_reply_num*1 + news_num*1 + + resource_num*5 + journal_num*1 + homework_journal_num*1 ) FROM `course_contributor_scores` AS ccs WHERE ccs.course_id = 577 AND ccs.user_id = members.user_id + ) AS act_score FROM members JOIN students_for_courses ON students_for_courses.student_id = members.user_id AND students_for_courses.course_id = members.course_id - WHERE members.course_id = #{@course.id} ORDER BY score #{score_sort_by}" + WHERE members.course_id = #{@course.id} ORDER BY #{sort_type} #{score_sort_by}" else sql_select = "SELECT members.*,( SELECT SUM(student_works.work_score) @@ -1171,11 +1190,13 @@ class CoursesController < ApplicationController WHERE student_works.homework_common_id = homework_commons.id AND homework_commons.course_id = #{@course.id} AND student_works.user_id = members.user_id - ) AS score + ) AS score,(SELECT (message_num*2 + message_reply_num*1 + news_reply_num*1 + news_num*1 + + resource_num*5 + journal_num*1 + homework_journal_num*1 ) FROM `course_contributor_scores` AS ccs WHERE ccs.course_id = 577 AND ccs.user_id = members.user_id + ) AS act_score FROM members JOIN students_for_courses ON students_for_courses.student_id = members.user_id AND students_for_courses.course_id = members.course_id - WHERE members.course_id = #{@course.id} AND members.course_group_id = #{groupid} ORDER BY score #{score_sort_by}" + WHERE members.course_id = #{@course.id} AND members.course_group_id = #{groupid} ORDER BY #{sort_type} #{score_sort_by}" end sql = ActiveRecord::Base.connection() homework_scores = Member.find_by_sql(sql_select) @@ -1225,8 +1246,7 @@ class CoursesController < ApplicationController sheet1[5,i+4] = "第"+(i+1).to_s+"次" end sheet1[5,homeworks.count+4] = "总成绩" - sheet1[5,0] = "排名" - sheet1[5,0] = "排名" + sheet1[5,homeworks.count+5] = "活跃度" count_row = 6 members.each_with_index do |member, i| sheet1[count_row,0]= i+1 @@ -1236,14 +1256,15 @@ class CoursesController < ApplicationController homeworks.each_with_index do |homework, j| student_works = homework.student_works.where("user_id = #{member.user.id}") if student_works.empty? - sheet1[count_row,j+4] = format("%0.2f",0) + sheet1[count_row,j+4] = 0 else final_score = student_works.first.final_score.nil? ? 0 : student_works.first.final_score score = final_score - student_works.first.absence_penalty - student_works.first.late_penalty - sheet1[count_row,j+4] = format("%0.2f",score <0 ? 0:score) + sheet1[count_row,j+4] = score <0 ? 0:score.round(2) end end - sheet1[count_row,homeworks.count+4] = format("%0.2f",member.score.nil? ? 0:member.score.to_s) + sheet1[count_row,homeworks.count+4] = member.score.nil? ? 0:member.score.round(2) + sheet1[count_row,homeworks.count+5] = member.act_score.nil? ? 0:member.act_score count_row += 1 end diff --git a/app/controllers/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb index d1a8b23dd..c6047d227 100644 --- a/app/controllers/org_document_comments_controller.rb +++ b/app/controllers/org_document_comments_controller.rb @@ -79,7 +79,7 @@ class OrgDocumentCommentsController < ApplicationController def add_reply @document = OrgDocumentComment.find(params[:id]).root - @act = OrgActivity.find(params[:id]) + @act = OrgActivity.find(params[:act_id]) @comment = OrgDocumentComment.new(:organization_id => @document.organization_id, :creator_id => User.current.id, :reply_id => params[:id]) @comment.content = params[:org_content] @document.children << @comment diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb index 661073cdc..c628b25fc 100644 --- a/app/controllers/org_subfields_controller.rb +++ b/app/controllers/org_subfields_controller.rb @@ -15,6 +15,12 @@ class OrgSubfieldsController < ApplicationController end end @subfield.update_attributes(:field_type => params[:field_type]) + # 如果栏目是教师,不参入类型的配置,定义为右三模式 + # 新增模块命名规则,左边1开头,右边2开头,以前的不变 + # eg:23 右三 + if params[:field_type] == "Comptec" + @subfield.update_attributes(:status => 23) + end else @res = false end diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 3709dd24b..c94f734e1 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -28,7 +28,7 @@ class OrganizationsController < ApplicationController helper :project_score helper :issues include UsersHelper - before_filter :find_organization, :only => [:show, :members, :apply_subdomain, :select_org_layout] + before_filter :find_organization, :only => [:show, :members, :apply_subdomain, :select_org_layout, :teachers] layout 'base_org' def index @@ -98,10 +98,26 @@ class OrganizationsController < ApplicationController else if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization) @organization = Organization.find(params[:id]) + # params[:org_subfield_id] 存在即对应的栏目,否则进入组织动态 if params[:org_subfield_id] @org_subfield = OrgSubfield.find(params[:org_subfield_id]) - @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0 - @org_activities = 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').page(params[:page] || 1).per(10) + if @org_subfield.field_type == "Comptec" || @org_subfield.field_type == "Compstu" + + # @org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,( SELECT `courses`.* FROM `courses` INNER JOIN `members` ON `courses`.`id` = `members`.`course_id` WHERE `members`.`user_id` = u.id AND (courses.status<>9)) as course_count + # from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 order by course_count desc") + @org_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 order by course_count desc") + # @org_count = @org_teachers.count + # @limit = 25 + # @is_remote = true + # @atta_count = @attachments.count + # @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + # @offset ||= @atta_pages.offset + # #@curse_attachments_all = @all_attachments[@offset, @limit] + # @attachments = paginateHelper @attachments,25 + else + @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0 + @org_activities = 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').page(params[:page] || 1).per(10) + end else shield_project_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Project'").map(&:shield_id) shield_course_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Course'").map(&:shield_id) @@ -142,6 +158,57 @@ class OrganizationsController < ApplicationController end + def teachers + unless @organization.allow_set_teachers + render_403 + return + end + q = params[:search].nil? ? "" : "#{params[:search].strip}" + @field = OrgSubfield.find(params[:org_subfield_id]) + @type = params[:type] + if @type == "courses" || @type.nil? + @org_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 concat(lastname,firstname,login) like '%#{q}%' order by course_count desc") + elsif @type == "students" + @org_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 concat(lastname,firstname,login) like '%#{q}%' order by course_count desc") + elsif @type == "resources" + @org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from attachments where attachments.author_id = u.id) as course_count + from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc") + elsif @type == "famous" + @org_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 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc") + end + limit = 10 + # @is_remote = true + @teachers_count = @org_teachers.count + @atta_pages = Paginator.new @teachers_count, limit, params['page'] || 1 + @offset ||= @atta_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @org_teachers = paginateHelper @org_teachers, limit + respond_to do |format| + format.html + format.js + end + end + + def searchmember_by_name members, name + #searchPeopleByRoles(project, StudentRoles) + mems = [] + if name != "" + name = name.to_s.downcase + members.each do |m| + username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase + if(m.user[:login].to_s.downcase.include?(name) || m.user.user_extensions[:student_id].to_s.downcase.include?(name) || username.include?(name)) + mems << m + end + end + else + mems = members + end + mems + end + def get_project_message_activities_org org project_ids = org.projects.map{|project| project.id}.join(",") unless project_ids.blank? @@ -221,6 +288,7 @@ class OrganizationsController < ApplicationController # @organization.domain = params[:organization][:domain] @organization.is_public = params[:organization][:is_public] == 'on' ? 1 : 0 @organization.allow_guest_download = params[:organization][:allow_guest_download] == 'on' ? 1 : 0 + @organization.allow_teacher = params[:organization][:allow_teacher] == 'on' ? 1 : 0 @organization.show_mode = params[:show_mode] #@organization.name = params[:organization][:name] @organization.save @@ -403,6 +471,18 @@ class OrganizationsController < ApplicationController end end + # 设置为名师 + def set_excellent_teacher + @ex_teacher = User.find(params[:user]) + @ex_teacher.update_column(:excellent_teacher, 1) + end + + # 取消名师 + def reset_excellent_teacher + @ex_teacher = User.find(params[:user]) + @ex_teacher.update_column(:excellent_teacher, 0) + end + def hide_org_subfield @org_subfield = OrgSubfield.find(params[:org_subfield_id]) @org_subfield.update_attribute(:hide, 1) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index b73ecf9b9..4a148bb8b 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -32,9 +32,9 @@ class RepositoriesController < ApplicationController before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo, :stats] before_filter :find_repository, :only => [:edit, :update, :destroy, :committers] - before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked] + before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked, :project_archive] before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue] - before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :commit_diff] + before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :commit_diff, :project_archive] accept_rss_auth :revisions # hidden repositories filter // 隐藏代码过滤器 before_filter :check_hidden_repo, :only => [:show, :stats, :revisions, :revision, :diff ] @@ -95,6 +95,13 @@ class RepositoriesController < ApplicationController end + # 一键ZIP下载 + def project_archive + g = Gitlab.client + g.get() + # g.project_archive(params[:gpid].to_i, params[:rev]) + end + # 判断用户是否已经fork过该项目 def has_forked?(project, user) projects = Project.where("user_id =?", user) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 121711a85..deab2feb6 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -123,6 +123,7 @@ class StudentWorkController < ApplicationController #-1 默认值 0全部正确并结束 2 超时 -2 编译错误 resultObj[:status] = -1 resultObj[:results] = result["results"].first #本次测试结果 + result["error_msg"] = result["error_msg"][0..2047] resultObj[:error_msg] = result["error_msg"] #编译错误时的信息 #该状态用于存入CodeTests @@ -499,6 +500,7 @@ class StudentWorkController < ApplicationController render_403 return end + @student_work_count = (search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}"),@name).count end @score = @b_sort == "desc" ? "asc" : "desc" diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8995a5aee..a81ade3fa 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -509,7 +509,7 @@ class UsersController < ApplicationController def choose_user_course homework = HomeworkCommon.find params[:send_id].to_i - if homework.course.is_public == 0 && !User.current.allowed_to?(:as_teacher,homework.course) + 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 @@ -630,9 +630,9 @@ class UsersController < ApplicationController 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" #我的题库 - courses = @user.courses.where("is_delete = 0") + 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 in #{course_ids}").order("#{@order} #{@b_sort}") + @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(",") + ")" @@ -672,7 +672,7 @@ class UsersController < ApplicationController def show_homework_detail homework = HomeworkCommon.find params[:homework].to_i - if homework.course.is_public == 0 && !User.current.allowed_to?(:as_teacher,homework.course) + 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 @@ -719,15 +719,15 @@ class UsersController < ApplicationController @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" #我的题库 - courses = @user.courses.where("is_delete = 0") + 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 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}" + 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 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}") + @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 in #{course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").order("#{@order} #{@b_sort}") + @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) @@ -2618,6 +2618,9 @@ class UsersController < ApplicationController # 获取我的资源 def get_my_resources author_id, user_course_ids, user_project_ids, order, score + unless author_id.to_i.to_s == author_id + author_id = User.find_by_login(author_id).id + end attachments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('OrgSubfield','Principal','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ "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)" + "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}") @@ -2625,6 +2628,7 @@ class UsersController < ApplicationController # 获取我的资源查询结果 def get_my_resources_search (author_id, user_course_ids, user_project_ids, order, score, search) + author_id = User.find_by_login(author_id).id @attachments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','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 is_publish = 1 and container_id is not null)" + "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)) and (filename like :p)" ,:p => search).order("#{order.nil? ? 'created_on' : order} #{score}") @@ -2632,6 +2636,7 @@ class UsersController < ApplicationController # 获取我的课程资源 def get_course_resources author_id, user_course_ids, order, score + author_id = User.find_by_login(author_id).id 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(',')}) and is_publish = 1 and container_id is not null)" ).order("#{order.nil? ? 'created_on' : order} #{score}") @@ -2639,6 +2644,7 @@ class UsersController < ApplicationController # 获取我的课程资源中搜索结果 def get_course_resources_search author_id, user_course_ids, order, score, search + author_id = User.find_by_login(author_id).id 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(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") @@ -2656,6 +2662,7 @@ class UsersController < ApplicationController # 获取我的项目资源 def get_project_resources author_id, user_project_ids, order, score + author_id = User.find_by_login(author_id).id 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(',')}) and is_publish = 1 and container_id is not null)").order("#{order.nil? ? 'created_on' : order} #{score}") @@ -2663,6 +2670,7 @@ class UsersController < ApplicationController # 获取我的项目资源搜索 def get_project_resources_search author_id, user_project_ids, order, score, search + author_id = User.find_by_login(author_id).id 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(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") @@ -2680,12 +2688,14 @@ class UsersController < ApplicationController # 获取我上传的附件 def get_attch_resources author_id, order, score + author_id = User.find_by_login(author_id).id attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue', 'Document','Message','News','StudentWorkScore','HomewCommon'))").order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我上传的附件搜索结果 def get_attch_resources_search author_id, order, score, search + author_id = User.find_by_login(author_id).id attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue', 'Document','Message','News','StudentWorkScore','HomewCommon')) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") end @@ -2704,11 +2714,13 @@ class UsersController < ApplicationController # 获取我的用户类型资源 def get_principal_resources author_id, order, score + author_id = User.find_by_login(author_id).id attchments = Attachment.where("author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal'").order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我的用户类型资源搜索 def get_principal_resources_search author_id, order, score, search + author_id = User.find_by_login(author_id).id attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal') and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") end @@ -2725,7 +2737,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 @@ -2780,13 +2792,13 @@ class UsersController < ApplicationController # 导入资源 def import_resources # 别人的资源库是没有权限去看的 - if User.current.id.to_i != params[:id].to_i + @user = User.find_by_login(params[:id]) + if User.current != @user 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} diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index bbf67f6a3..229aceb1c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -33,6 +33,19 @@ module ApplicationHelper extend Forwardable def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter + + def user_path(resource, parameters = {}) + if Fixnum === resource + resource = User.find(resource) + end + super + end + + # def user_blogs_path(resource,parameters={}) + # super + # end + + def update_visiti_count container container.update_column(:visits, container.visits + 1) end diff --git a/app/helpers/organizations_helper.rb b/app/helpers/organizations_helper.rb index 917ccc01c..cba4fa210 100644 --- a/app/helpers/organizations_helper.rb +++ b/app/helpers/organizations_helper.rb @@ -148,4 +148,43 @@ module OrganizationsHelper 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/models/homework_common.rb b/app/models/homework_common.rb index 998ace441..f11a48a80 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -29,8 +29,8 @@ 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_update :update_activity, :wechat_message + after_create :act_as_activity, :send_mail + after_update :update_activity after_save :act_as_course_activity after_destroy :delete_kindeditor_assets @@ -60,11 +60,11 @@ class HomeworkCommon < ActiveRecord::Base 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) - 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 + #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 # end end end diff --git a/app/models/issue.rb b/app/models/issue.rb index 79ddcd917..d5d148117 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -262,7 +262,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/journals_for_message.rb b/app/models/journals_for_message.rb index 4b5ac227f..68b747ab9 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -260,6 +260,10 @@ class JournalsForMessage < ActiveRecord::Base 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) 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) + end end 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 diff --git a/app/models/organization.rb b/app/models/organization.rb index 8f9d290eb..311a37bf8 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -26,4 +26,8 @@ class Organization < ActiveRecord::Base 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 end 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/user.rb b/app/models/user.rb index 9e4f227b7..035aff625 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -309,6 +309,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 # 查询用户未读过的记录 # 用户留言记录 @@ -1073,16 +1087,25 @@ 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 + + def to_param + login + 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/views/courses/_courses_jours.html.erb b/app/views/courses/_courses_jours.html.erb index c7e4a7428..1050a59b9 100644 --- a/app/views/courses/_courses_jours.html.erb +++ b/app/views/courses/_courses_jours.html.erb @@ -36,7 +36,7 @@
取消 - 留言 + 留言 <% end %> <% end %> @@ -55,9 +55,6 @@ \ No newline at end of file diff --git a/app/views/exercise/_new_MCQ.html.erb b/app/views/exercise/_new_MCQ.html.erb index a24835fc1..875b9ec4c 100644 --- a/app/views/exercise/_new_MCQ.html.erb +++ b/app/views/exercise/_new_MCQ.html.erb @@ -54,9 +54,16 @@ -<% end %> \ No newline at end of file +<% end %> + \ No newline at end of file diff --git a/app/views/exercise/_new_single.html.erb b/app/views/exercise/_new_single.html.erb index 6180dac8e..24a0ad047 100644 --- a/app/views/exercise/_new_single.html.erb +++ b/app/views/exercise/_new_single.html.erb @@ -42,9 +42,16 @@ -<% end %> \ No newline at end of file +<% end %> + \ No newline at end of file diff --git a/app/views/exercise/_show_MC.html.erb b/app/views/exercise/_show_MC.html.erb index eef7546e5..99c48a3ab 100644 --- a/app/views/exercise/_show_MC.html.erb +++ b/app/views/exercise/_show_MC.html.erb @@ -90,7 +90,7 @@ ''+ ''+ ' '+ ' '+ ' -diff --git a/app/views/layouts/base_sub_domain.html.erb b/app/views/layouts/base_sub_domain.html.erb index b2d26d309..871e2cdea 100644 --- a/app/views/layouts/base_sub_domain.html.erb +++ b/app/views/layouts/base_sub_domain.html.erb @@ -1,187 +1,191 @@ - - -
- -
- - - <%= csrf_meta_tag %> - <%= favicon %> - <%= javascript_heads %> - <%= heads_for_theme %> - <%= stylesheet_link_tag 'org_new_style','jquery/jquery-ui-1.9.2', 'org2' %> - <%= javascript_include_tag 'cookie','project', 'organization','header','prettify','select_list_move','org'%> - <%= javascript_include_tag 'attachments' %> - <%#= call_hook :view_layouts_base_html_head %> - - <%#= yield :header_tags -%> - - - - - - - - - - - - - -
-