diff --git a/1234567 b/1234567 index e9cd9a1c1..08de77ab4 100644 --- a/1234567 +++ b/1234567 @@ -1 +1 @@ -{"access_token":"yFUfEXFu0_Pl_jdojoRv6eA8pmGjyRkRIL1VCB2HZ4kVJhEq6crriyCRCI-_u5QbWgtepiIOvqTHtXpKgzMuaB7Eo7MjlMcXeecqhzTjnvpivK5HUzGhZXBG1dk_BxicJAFlCAARIN","expires_in":7200,"got_token_at":1461934858} \ No newline at end of file +{"access_token":"bFlabz0uBcoIBfWL7nBJkgpl26aOWDy-dyCOvH_MjUo_hMOOKG83WV1cCL1MG6H-AE-6eMI0iyLoOoAMv9Y3pFFsLYD-GAGr3UH9fT8OqeHMDlFhXyRTvHv9l2QPHGpcARUcCGANEH","expires_in":7200,"got_token_at":1462934760} \ No newline at end of file diff --git a/Gemfile b/Gemfile index f3b06c2d4..9f31edad1 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/assets/javascripts/sub_document_comments.js.coffee b/app/assets/javascripts/sub_document_comments.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/sub_document_comments.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/sub_domains.js.coffee b/app/assets/javascripts/sub_domains.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/sub_domains.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/sub_document_comments.css.scss b/app/assets/stylesheets/sub_document_comments.css.scss new file mode 100644 index 000000000..c88f77750 --- /dev/null +++ b/app/assets/stylesheets/sub_document_comments.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the sub_document_comments controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/sub_domains.css.scss b/app/assets/stylesheets/sub_domains.css.scss new file mode 100644 index 000000000..7a751c0d9 --- /dev/null +++ b/app/assets/stylesheets/sub_domains.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the sub_domains controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 8ae20972c..d3f681a06 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -593,7 +593,7 @@ class AdminController < ApplicationController end end - #代码测试列表 +#代码测试列表 def code_work_tests #求出所有条数 tCount = CodeTests.count() @@ -644,4 +644,13 @@ class AdminController < ApplicationController format.html end end + #分享作业申请 + def apply_for_homework + homeworks = ApplyHomework.where("user_id != 0") + @homework = paginateHelper homeworks,30 + @page = (params['page'] || 1).to_i - 1 + respond_to do |format| + format.html + end + end end diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index 1d7e94c06..9a72bb4df 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -125,7 +125,7 @@ class BoardsController < ApplicationController if @order.to_i == 2 @type = 2 @topics.each do |topic| - topic[:infocount] = get_praise_num(topic) + (topic.parent ? x.parent.children.count : topic.children.count) + topic[:infocount] = get_praise_num(topic) + (topic.parent ? topic.parent.children.count : topic.children.count) if topic[:infocount] < 0 topic[:infocount] = 0 end diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index fabacf1ba..689ef2bd7 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -11,6 +11,9 @@ class HomeworkCommonController < ApplicationController before_filter :member_of_course, :only => [:index] def index + #unless params[:page] + # update_homework_time(@course.homework_commons) + #end @new_homework = HomeworkCommon.new @new_homework.homework_detail_manual = HomeworkDetailManual.new @new_homework.course = @course @@ -400,4 +403,47 @@ class HomeworkCommonController < ApplicationController student_works += student_works student_works[index + 1 .. index + n] end + + def update_homework_time homeworks + unless homeworks.nil? + homeworks.each do |h| + if h.homework_type == 3 + student_works = h.student_work_projects.where("is_leader = 1") + time = h.updated_at + unless student_works.nil? + student_works.each do |s| + project = Project.find s.project_id + unless project.nil? && project.gpid.nil? + project_time=project.updated_on + project_time=ForgeActivity.where("project_id=?",project.id).last.updated_at if ForgeActivity.where("project_id=?",project.id).last + if format_time(time) < format_time(project_time) + time = project_time + end + begin + # gitlab端获取默认分支 + g = Gitlab.client + default_branch = g.project(project.gpid).default_branch + changesets = g.commits(project.gpid, :ref_name => default_branch) + changesets_latest_coimmit = changesets[0] + unless changesets[0].blank? + if format_time(time) < format_time(changesets_latest_coimmit.created_at) + time = changesets_latest_coimmit.created_at + end + end + rescue + logger.error("############## ==> update homework project time") + end + end + end + end + puts h.updated_at + puts time + s_time = time + if format_time(time) > format_time(h.updated_at) + h.update_attribute(:updated_at, s_time) + end + end + end + end + end end diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index d35d7ac63..76b229dbf 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -83,6 +83,8 @@ class NewsController < ApplicationController sort_type = @b_sort == 1 ? "asc" : "desc" + #scope = News.find_by_sql("select a.*,b.updated_at from news a, course_activities b where a.course_id = 532 and a.course_id = b.course_id and b.course_act_id = a.id ) ") + scope = @course ? @course.news.course_visible : News.course_visible news_arr = scope.map{|news| news.id} @@ -101,7 +103,8 @@ class NewsController < ApplicationController end scope_order.each do |topic| - topic[:updated_at] = CourseActivity.where("course_act_type='#{topic.class}' and course_act_id =#{topic.id}").first.updated_at + topic[:updated_at] = topic.course_acts.first.updated_at + #topic[:updated_at] = CourseActivity.where("course_act_type='#{topic.class}' and course_act_id =#{topic.id}").first.updated_at 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 f3c01f21e..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 @@ -76,7 +76,7 @@ class OrganizationsController < ApplicationController def show # 组织新类型 show_mode:判断标准 1为新类型,0为旧 - if @organization.show_mode == 1 && params[:org_subfield_id].nil? && params[:list] .nil? + if @organization.show_mode.to_i == 1 && params[:org_subfield_id].nil? && params[:list] .nil? if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization) # REDO:时间紧,暂时先这样 @org_logo_attchment = Attachment.find_by_sql("SELECT * from attachments WHERE container_id = #{@organization.id} and container_type = 'Organization' and attachtype = 0 and filename REGEXP '(.jpg|.png|.bmp|.gif|.jpeg)' ORDER BY created_on desc limit 1").first @@ -84,10 +84,6 @@ class OrganizationsController < ApplicationController @subfield_content = @organization.org_subfields.order("priority") @organization = Organization.find(params[:id]) - # @org_subfield = OrgSubfield.find(params[:org_subfield_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').page(params[:page] || 1).per(10) - 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) project_ids = (@organization.projects.map(&:id)-shield_project_ids) << 0 @@ -95,35 +91,33 @@ class OrganizationsController < ApplicationController course_types = "('Message','News','HomeworkCommon','Poll','Course')" @project_acts = get_project_activities_org @organization, project_ids @course_acts = get_course_activities_org @organization, course_ids - #@org_acts = OrgActivity.where("container_id =? and container_type =?",@organization.id, 'Organization').order('updated_at desc') - #@project_acts = OrgActivity.where("(container_id =? and container_type =?) " + - # "or (container_type ='Project' and org_act_type in ('Issue','Message') and container_id in (#{project_ids.join(',')})) ", - # @organization.id, 'Organization').order('updated_at desc').limit(8) - - #@course_acts = OrgActivity.where("(container_id =? and container_type =?) " + - # "or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))", - # @organization.id, 'Organization').order('updated_at desc').limit(8) - - - - # 项目两种动态 - #@project_acts = get_project_activities_org @organization - - # 课程动态 - #@project_acts_issues = get_project_activities_org @organization - #@course_acts = get_course_activities_org @organization - - render :layout => 'base_org_newstyle' + render :layout => 'base_org2' else render_403 end 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) @@ -164,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? @@ -187,7 +232,7 @@ class OrganizationsController < ApplicationController def get_project_activities_org org, project_ids unless project_ids.blank? project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{project_ids.join(',')}) and container_type = 'project' - and org_act_type in ('Message', 'Issue') order by updated_at desc limit 8;") + and org_act_type in ('Message', 'Issue') order by updated_at desc limit 5;") else project_acts = nil end @@ -198,7 +243,7 @@ class OrganizationsController < ApplicationController def get_course_activities_org org, course_ids unless course_ids.blank? project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{course_ids.join(',')}) and container_type = 'course' - and org_act_type in ('HomeworkCommon', 'Poll', 'Message', 'News', 'Course') order by updated_at desc limit 8;") + and org_act_type in ('HomeworkCommon', 'Poll', 'Message', 'News', 'Course') order by updated_at desc limit 5;") else project_acts = nil end @@ -243,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 @@ -425,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 cc1a1e9c7..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" @@ -760,49 +762,64 @@ class StudentWorkController < ApplicationController #老师、教辅可以随时评分,学生只能在匿评作业的匿评阶段进行评分 render_403 and return unless @is_teacher || @homework.homework_detail_manual.comment_status == 2 @score = student_work_score @work,User.current + #@score.comment = params[:new_form][:user_message] if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != "" + #@score.score = params[:score] if params[:score] + #if User.current.admin? + # @score.reviewer_role = 1 + #else + # role = User.current.members.where("course_id = ?",@course.id).first.roles.first.name + # @score.reviewer_role = get_role_by_name(role) + #end + #@is_new = false + @is_last_a = @work.student_works_scores.empty? + @new_score = StudentWorksScore.new + if @score && params[:score] + @new_score.score = params[:score].to_i == -1 ? @score.score : params[:score] + elsif @score.nil? && params[:score] + @new_score.score = params[:score].to_i == -1 ? nil : params[:score] + end + @new_score.comment = params[:new_form][:user_message] if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != "" + @new_score.user_id = User.current.id + @new_score.student_work_id = @work.id + if User.current.admin? + @new_score.reviewer_role = 1 + else + role = User.current.members.where("course_id = ?",@course.id).first.roles.first.name + @new_score.reviewer_role = get_role_by_name(role) + end if @score - @score.comment = params[:new_form][:user_message] if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != "" - @score.score = params[:score] if params[:score] - if User.current.admin? - @score.reviewer_role = 1 + if @is_teacher + @is_new = true + @is_last_a = false else - role = User.current.members.where("course_id = ?",@course.id).first.roles.first.name - @score.reviewer_role = get_role_by_name(role) + @is_new = false end - @is_new = false else - @is_last_a = @work.student_works_scores.empty? - @score = StudentWorksScore.new - @score.score = params[:score] if params[:score] - @score.comment = params[:new_form][:user_message] if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != "" - @score.user_id = User.current.id - @score.student_work_id = @work.id - if User.current.admin? - @score.reviewer_role = 1 - else - role = User.current.members.where("course_id = ?",@course.id).first.roles.first.name - @score.reviewer_role = get_role_by_name(role) - end @is_new = true end - @score.save_attachments(params[:attachments]) - render_attachment_warning_if_needed(@score) + @new_score.save_attachments(params[:attachments]) + render_attachment_warning_if_needed(@new_score) - if @score.save - case @score.reviewer_role + if @new_score.save + case @new_score.reviewer_role when 1 #教师评分:最后一个教师评分为最终评分 - @work.teacher_score = @score.score + @work.teacher_score = @new_score.score when 2 #教辅评分 教辅评分显示平均分 - @work.teaching_asistant_score = @work.student_works_scores.where(:reviewer_role => 2).average(:score).try(:round, 2).to_f + #@work.teaching_asistant_score = @work.student_works_scores.where(:reviewer_role => 2).average(:score).try(:round, 2).to_f + ts_score = StudentWorksScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id = #{@work.id} AND reviewer_role = 2 AND score IS NOT NULL ORDER BY created_at DESC) AS t GROUP BY user_id) AS a") + @work.teaching_asistant_score = ts_score.first.score.nil? ? nil : ts_score.first.score.try(:round, 2).to_f when 3 #学生评分 学生评分显示平均分 - @work.student_score = @work.student_works_scores.where(:reviewer_role => 3).average(:score).try(:round, 2).to_f + #@work.student_score = @work.student_works_scores.where(:reviewer_role => 3).average(:score).try(:round, 2).to_f + stu_score = StudentWorksScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id = #{@work.id} AND reviewer_role = 3 ORDER BY created_at DESC) AS t GROUP BY user_id) AS a") + @work.student_score = stu_score.first.score.try(:round, 2).to_f end @homework.update_attributes(: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) if @work.save + @work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => @work.id).first respond_to do |format| format.js end @@ -835,6 +852,14 @@ class StudentWorkController < ApplicationController end end + #提交未评分的评语 + def add_comments_to_work + @work = StudentWork.find params[:id] + respond_to do |format| + format.js + end + end + #为作品点赞 def praise_student_work pt = PraiseTread.new @@ -990,6 +1015,10 @@ class StudentWorkController < ApplicationController end attachment = @work.attachments.where("attachtype = 7").first attachment.update_attributes(:description => params[:description]) + if attachment.attachtype == 7 + student_work = StudentWork.find attachment.container_id + CourseMessage.create(:user_id => student_work.homework_common.user_id, :course_id => student_work.homework_common.course_id, :viewed => false,:course_message_id=>attachment.container_id,:course_message_type=>'StudentWork',:status=>2) + end respond_to do |format| format.js end @@ -1147,7 +1176,7 @@ class StudentWorkController < ApplicationController blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 sheet1.row(0).default_format = blue if @homework.homework_type == 1 #匿评作业 - sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name), + sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),l(:excel_homework_des), l(:excel_t_score),l(:excel_ta_score), l(:excel_n_score),l(:excel_f_score),l(:excel_commit_time)]) count_row = 1 items.each do |homework| @@ -1157,15 +1186,16 @@ class StudentWorkController < ApplicationController sheet1[count_row,3] = homework.user.user_extensions.student_id sheet1[count_row,4] = homework.user.mail sheet1[count_row,5] = homework.name - sheet1[count_row,6] = homework.teacher_score.nil? ? l(:label_without_score) : format("%.2f",homework.teacher_score) - sheet1[count_row,7] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : format("%.2f",homework.teaching_asistant_score) - sheet1[count_row,8] = homework.student_score.nil? ? l(:label_without_score) : format("%.2f",homework.student_score) - sheet1[count_row,9] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : format("%.2f",homework.score) : l(:label_without_score) - sheet1[count_row,10] = format_time(homework.created_at) + sheet1[count_row,6] = strip_html homework.description + sheet1[count_row,7] = homework.teacher_score.nil? ? l(:label_without_score) : homework.teacher_score.round(2) + sheet1[count_row,8] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : homework.teaching_asistant_score.round(2) + sheet1[count_row,9] = homework.student_score.nil? ? l(:label_without_score) : homework.student_score.round(2) + sheet1[count_row,10] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score) + sheet1[count_row,11] = format_time(homework.created_at) count_row += 1 end elsif @homework.homework_type == 2 #编程作业 - sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name), + sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),l(:excel_homework_des), l(:excel_t_score),l(:excel_ta_score), l(:excel_s_score),l(:excel_n_score),l(:excel_f_score),l(:excel_commit_time)]) count_row = 1 items.each do |homework| @@ -1175,12 +1205,13 @@ class StudentWorkController < ApplicationController sheet1[count_row,3] = homework.user.user_extensions.student_id sheet1[count_row,4] = homework.user.mail sheet1[count_row,5] = homework.name - sheet1[count_row,6] = homework.teacher_score.nil? ? l(:label_without_score) : format("%.2f",homework.teacher_score) - sheet1[count_row,7] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : format("%.2f",homework.teaching_asistant_score) - sheet1[count_row,8] = homework.system_score.nil? ? l(:label_without_score) : format("%.2f",homework.system_score) - sheet1[count_row,9] = homework.student_score.nil? ? l(:label_without_score) : format("%.2f",homework.student_score) - sheet1[count_row,10] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : format("%.2f",homework.score) : l(:label_without_score) - sheet1[count_row,11] = format_time(homework.created_at) + sheet1[count_row,6] = homework.description + sheet1[count_row,7] = homework.teacher_score.nil? ? l(:label_without_score) : homework.teacher_score.round(2) + sheet1[count_row,8] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : homework.teaching_asistant_score.round(2) + sheet1[count_row,9] = homework.system_score.nil? ? l(:label_without_score) : homework.system_score.round(2) + sheet1[count_row,10] = homework.student_score.nil? ? l(:label_without_score) : homework.student_score.round(2) + sheet1[count_row,11] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score) + sheet1[count_row,12] = format_time(homework.created_at) count_row += 1 end end diff --git a/app/controllers/sub_document_comments_controller.rb b/app/controllers/sub_document_comments_controller.rb new file mode 100644 index 000000000..767e1ba29 --- /dev/null +++ b/app/controllers/sub_document_comments_controller.rb @@ -0,0 +1,208 @@ +class SubDocumentCommentsController < ApplicationController + before_filter :find_subdomain_and_subfield, :only => [:new, :create, :show, :index, :destroy, :edit] + before_filter :find_subfield_content, :only => [:show, :index] + helper :attachments,:organizations + layout 'base_sub_domain' + + def new + @sub_document_comment = SubDocumentComment.new + end + + + def create + @sub_document_comment = SubDocumentComment.new(:sub_domain_id => params[:sub_domain_id], :creator_id => User.current.id, :org_subfield_id => params[:org_subfield_id]) + @sub_document_comment.title = params[:sub_document_comment][:title] + @sub_document_comment.content = params[:sub_document_comment][:content] + # @sub_document_comment.save_attachments(params[:attachments]) + if params[:field_id] + @sub_document_comment.org_subfield_id = params[:field_id].to_i + end + if @sub_document_comment.save + flash.keep[:notice] = l(:notice_successful_create) + redirect_to org_subfield_sub_domain_sub_document_comments_path(:org_subfield_id => @org_subfield.id, :sub_domain_id => @subdomain.id) + # EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @sub_document_comment.id, :created_at => @sub_document_comment.updated_at) + # if params[:field_id] + # @org_subfield = OrgSubfield.find(params[:field_id]) + # if @org_subfield.subfield_subdomain_dir.nil? + # redirect_to organization_path(@organization, :org_subfield_id => params[:field_id]) + # else + # redirect_to show_org_subfield_organization_path(:id => @organization.id, :sub_dir_name => @org_subfield.subfield_subdomain_dir.name) + # end + # else + # redirect_to organization_org_document_comments_path(@organization) + # end + else + redirect_to new_org_document_comment_path(:organization_id => @organization.id) + end + end + + def show + if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization) + @document = SubDocumentComment.find(params[:id]) + respond_to do |format| + format.html {render :layout => @organization.switch_type ? 'base_sub_domain' : 'base_org'} + end + else + render_403 + end + end + + def index + if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization) + @documents = @subdomain.sub_document_comments.where("parent_id is null").order("created_at desc") + @is_remote = true + @limit = 20 + @atta_count = @documents.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + @documents = paginateHelper @documents,20 + respond_to do |format| + format.html {render :layout => @organization.switch_type ? 'base_sub_domain' : 'base_org'} + end + else + render_403 + end + end + + def update + @sub_document = SubDocumentComment.find(params[:id]) + @sub_document.update_attributes(:title => params[:sub_document_comment][:title], :content => params[:sub_document_comment][:content]) + @organization = OrgSubfield.find(params[:org_subfield_id]).organization + # Attachment.attach_files(@org_document, params[:attachments]) + # @org_document.save_attachments(params[:attachments]) + if @sub_document.parent.nil? + act = OrgActivity.where("org_act_type='SubDocumentComment' and org_act_id =?", @sub_document.id).first + act.update_attributes(:updated_at => @sub_document.updated_at) + # EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @org_document.id, :created_at => Time.now) + end + respond_to do |format| + format.html { + if params[:flag].to_i == 0 + + # render :action => 'index', :layout => @organization.switch_type ? 'base_sub_domain' : 'base_org' + redirect_to org_subfield_sub_domain_sub_document_comments_path(:org_subfield_id => params[:org_subfield_id], :sub_domain_id => params[:sub_domain_id]) + # render :layout => @organization.switch_type ? 'base_sub_domain' : 'base_org' + # redirect_to organization_path(@organization) + else + redirect_to org_subfield_sub_domain_sub_document_comment_path(:org_subfield_id => params[:org_subfield_id], :sub_domain_id => params[:sub_domain_id]) + end + } + end + end + + def edit + @sub_document = SubDocumentComment.find(params[:id]) + @flag = params[:flag] + render :layout => @organization.switch_type ? 'base_sub_domain' : 'base_org' + end + + def add_reply + @document = SubDocumentComment.find(params[:id]).root + @subdomain = @document.sub_domain + @org_subfield = @subdomain.org_subfield + @organization = @org_subfield.organization + @act = OrgActivity.find(params[:id]) + @comment = SubDocumentComment.new(:sub_domain_id => @document.sub_domain, :creator_id => User.current.id, :reply_id => params[:id]) + @comment.content = params[:sub_content] + @document.children << @comment + @document.save + end + + def add_reply_in_doc + @document = SubDocumentComment.find(params[:id]).root + @subdomain = @document.sub_domain + @org_subfield = @subdomain.org_subfield + @organization = @org_subfield.organization + @comment = SubDocumentComment.new(:sub_domain_id => @document.sub_domain_id, :creator_id => User.current.id, :reply_id => params[:id]) + @comment.content = params[:flag] ? params[:sub_content] : params[:org_comment][:sub_content] + @document.children << @comment + @document.save + respond_to do |format| + format.html {redirect_to org_subfield_sub_domain_sub_document_comment_path(:id => @document.id, :org_subfield_id => @org_subfield.id, :sub_domain_id => @subdomain.id)} + end + end + + def destroy + @sub_document_comment = SubDocumentComment.find(params[:id]) + @sub_document_comment.destroy + rescue ActiveRecord::RecordNotFound + respond_to do |format| + # format.html{ + # redirect_to org_subfield_sub_domain_sub_document_comments_path(:id => params[:sub_domain_id], :org_subfield_id => params[:org_subfield_id]) + # } + format.js + end + end + + def delete_reply + @sub_document_comment = OrgDocumentComment.find(params[:id]) + @document = @sub_document_comment.root + org = @sub_document_comment.organization + @sub_document_comment.destroy + respond_to do |format| + format.html {redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)} + end + end + def quote + @org_comment = OrgDocumentComment.find(params[:id]) + @subject = @org_comment.content + @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:') + + @content = "> #{ll(Setting.default_language, :text_user_wrote, User.find(@org_comment.creator_id).realname)}\n> " + @temp = OrgDocumentComment.new + #@course_id = params[:course_id] + @temp.content = "
#{ll(Setting.default_language, :text_user_wrote, User.find(@org_comment.creator_id).realname)}
#{@org_comment.content.html_safe}
".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 f8bf70933..a81ade3fa 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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| @@ -396,6 +419,19 @@ class UsersController < ApplicationController 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_homework if User.current.logged? @@ -405,7 +441,7 @@ class UsersController < ApplicationController 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) + 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 @@ -452,7 +488,7 @@ class UsersController < ApplicationController user_course_ids = @user.courses.empty? ? "(-1)" :"(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" #判断当前用户在当前课程的身份 - visibleCourse = @user.courses.empty? ? [] : @user.courses.visible + 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}'") @@ -473,7 +509,7 @@ class UsersController < ApplicationController def choose_user_course homework = HomeworkCommon.find params[:send_id].to_i - if homework.course.is_public == 0 && homework.user_id != User.current.id + 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 @@ -586,26 +622,39 @@ class UsersController < ApplicationController @r_sort = @b_sort == "desc" ? "asc" : "desc" @user = User.current if(params[:type].blank? || params[:type] == "1") #题库 - visible_course = Course.where("is_delete = 0") + 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" #我的题库 - 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" #申请题库 - #apply_homeworks = ApplyHomework.where("user_id = ?",@user.id) + 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}") - 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} order by ah.created_at desc" + #@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] && 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}") + 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] @@ -622,7 +671,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 @@ -637,7 +700,11 @@ class UsersController < ApplicationController 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_delete = 0") + 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} @@ -652,26 +719,28 @@ 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) 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.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}" + 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("homework_commons.id in #{homework_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}") + @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("id in #{homework_ids} 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 @@ -1208,13 +1277,13 @@ class UsersController < ApplicationController #显示更多用户课程 def user_courses4show @page = params[:page].to_i + 1 - @courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5).offset(@page * 5) + @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 a").order("a desc").limit(5).offset(@page * 5) end #显示更多用户项目 def user_projects4show @page = params[:page].to_i + 1 - @projects = @user.projects.visible.select("projects.*,(SELECT MAX(created_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5).offset(@page * 5) + @projects = @user.projects.visible.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5).offset(@page * 5) end def user_course_activities @@ -1302,7 +1371,7 @@ 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')" principal_types = "JournalsForMessage" @@ -2549,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}") @@ -2556,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}") @@ -2563,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}") @@ -2570,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}") @@ -2587,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}") @@ -2594,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}") @@ -2611,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 @@ -2635,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 @@ -2656,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 @@ -2711,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} @@ -2945,10 +3026,11 @@ class UsersController < ApplicationController @c_sort = 2 end - sort_name = "created_at" + sort_name = "updated_on" sort_type = @c_sort == 1 ? "asc" : "desc" - @courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a #{sort_type}") + # @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 @@ -2989,10 +3071,11 @@ class UsersController < ApplicationController @c_sort = 2 end - sort_name = "created_on" + sort_name = "updated_at" sort_type = @c_sort == 1 ? "asc" : "desc" - @projects = @user.projects.visible.select("projects.*, (SELECT MAX(created_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a #{sort_type}") + #@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 diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index 0d75636f7..30f56a1d9 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 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 d2f3ad456..229aceb1c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -33,10 +33,29 @@ 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 + 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 + # Time 2015-03-24 15:27:29 # Author lizanle # Description 从硬盘上删除对应的资源文件 @@ -2953,6 +2972,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,9 +3010,11 @@ 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, is_focus = '') +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 @@ -3065,6 +3094,16 @@ def host_with_protocol return Setting.protocol + "://" + Setting.host_name 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 = [] @@ -3208,4 +3247,4 @@ def strip_html(text,len=0,endss="...") end end return ss -end +end diff --git a/app/helpers/organizations_helper.rb b/app/helpers/organizations_helper.rb index b3b014de1..cba4fa210 100644 --- a/app/helpers/organizations_helper.rb +++ b/app/helpers/organizations_helper.rb @@ -5,17 +5,17 @@ module OrganizationsHelper def find_user_not_in_current_org_by_name org - if params[:q] && params[:q].lstrip.rstrip != "" - scope = Principal.active.sorted.not_member_of_org(org).like(params[:q]) - else - scope = [] - end - principals = paginateHelper scope,10 - s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals') - links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options| - link_to text, org_member_autocomplete_org_member_index_path( parameters.merge(:q => params[:q],:flag => true,:org=>org, :format => 'js')), :remote => true - } - s + content_tag('ul', links,:class => 'wlist',:style=>'float:left !important', :id => "org_member_pagination_links" ) + if params[:q] && params[:q].lstrip.rstrip != "" + scope = Principal.active.sorted.not_member_of_org(org).like(params[:q]) + else + scope = [] + end + principals = paginateHelper scope,10 + s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals') + links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options| + link_to text, org_member_autocomplete_org_member_index_path( parameters.merge(:q => params[:q],:flag => true,:org=>org, :format => 'js')), :remote => true + } + s + content_tag('ul', links,:class => 'wlist',:style=>'float:left !important', :id => "org_member_pagination_links" ) end def get_default_name field @@ -63,14 +63,128 @@ module OrganizationsHelper def subfield_status_option type = [] option1 = [] - option1 << "列表" + option1 << "左一" + option1 << "1" + type << option1 + # 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 - option2 = [] - option2 << "图片" - option2 << "0" - type << option2 + 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/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 index 0a7c505a4..f4ded9733 100644 --- a/app/models/apply_homework.rb +++ b/app/models/apply_homework.rb @@ -1,5 +1,5 @@ class ApplyHomework < ActiveRecord::Base - #status:1. 待审核 2.审核通过 3.已拒绝 + #status:1. 等待回复 2.审核通过 3.已拒绝 belongs_to :user belongs_to :homework_common attr_accessible :status, :user_id, :homework_common_id diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 754bd4dee..b3f5ce4ed 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -301,7 +301,7 @@ class Attachment < ActiveRecord::Base nil end - def filename=(arg) + def filename=(arg) write_attribute :filename, sanitize_filename(arg.to_s) filename end diff --git a/app/models/course_message.rb b/app/models/course_message.rb index 07bfb22de..703da936b 100644 --- a/app/models/course_message.rb +++ b/app/models/course_message.rb @@ -15,7 +15,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/homework_common.rb b/app/models/homework_common.rb index dae910d60..998ace441 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 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 10971d46f..4b5ac227f 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -256,6 +256,11 @@ class JournalsForMessage < ActiveRecord::Base end end 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) + 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 ws = WechatService.new diff --git a/app/models/news.rb b/app/models/news.rb index 1a2205f48..f0457dc81 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 after_update :update_activity after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities, :down_course_score 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..311a37bf8 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -22,4 +22,12 @@ 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 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/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 9b8cb2b8d..035aff625 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -108,6 +108,7 @@ 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 #end has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)}, @@ -308,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 # 查询用户未读过的记录 # 用户留言记录 @@ -1072,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/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 @@ +

+ <%=l(:label_apply_homework)%> +

+ +
+ + + + + + + + + + + + + + <%@count=@page*30 %> + <% for homework in @homework do %> + <% unless homework.nil? %> + <% @count+=1 %> + + + <% c_h = HomeworkCommon.find homework.homework_common_id %> + <% if c_h %> + + <% if c_h.course %> + + <% end %> + + <% end %> + + + + + <% end %> + <% end %> + +
+ 序号 + + 作业名称 + + 课程名称 + + 作者 + + 申请者 + + 申请状态 + + 申请日期 +
+ <%=@count %> + + <%=link_to(c_h.try(:name), student_work_index_path(:homework => c_h.id))%> + + <%= link_to(c_h.course.name, course_path(c_h.course.id)) %> + <%= c_h.try(:user)%><% else %><%=c_h.try(:user).try(:realname) %><% end %>'> + <% if c_h.try(:user).try(:realname) == ' '%> + <%= link_to(c_h.try(:user), user_path(c_h.user_id)) %> + <% else %> + <%= link_to(c_h.try(:user).try(:realname), user_path(c_h.user_id)) %> + <% end %> + <%= homework.try(:user)%><% else %><%=homework.try(:user).try(:realname) %><% end %>'> + <% if homework.try(:user).try(:realname) == ' '%> + <%= link_to(homework.try(:user), user_path(homework.user_id)) %> + <% else %> + <%= link_to(homework.try(:user).try(:realname), user_path(homework.user_id)) %> + <% end %> + + <% if homework.status == 1 %> + 等待回复 + <% elsif homework.status == 2 %> + 已通过 + <% else %> + 已拒绝 + <% end %> + + <%=format_date( homework.created_at ) %> +
+
+ + + +<% html_title(l(:label_apply_homework)) -%> diff --git a/app/views/blogs/_article.html.erb b/app/views/blogs/_article.html.erb index 7a1dc636c..f0b082860 100644 --- a/app/views/blogs/_article.html.erb +++ b/app/views/blogs/_article.html.erb @@ -16,6 +16,7 @@
+ <% if topics.any? %> <% topics.each do |activity| %>
+ <% else %> +

<%= l(:label_no_data) %>

+ <% end %> diff --git a/app/views/boards/_course_new.html.erb b/app/views/boards/_course_new.html.erb index 3deb04f6c..df61d2b9c 100644 --- a/app/views/boards/_course_new.html.erb +++ b/app/views/boards/_course_new.html.erb @@ -2,6 +2,7 @@ <%= import_ke(enable_at: true, prettify: false, init_activity: false) %> <% end %> \ 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 @@ ''+ ''+ ''+ ''+ ' <% end %> - + <% else %>

<%= l(:label_no_data) %>

<% end %> diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erb index b0ed5a60c..61ffb8b10 100644 --- a/app/views/forums/show.html.erb +++ b/app/views/forums/show.html.erb @@ -41,9 +41,6 @@
<%= render :partial => 'show_topics',:locals => {:memos=>@memos}%>
- @@ -112,11 +109,13 @@ <% end %> }); + var first_click = true; function check_and_submit(){ if(!check_memo_name()){ return; } - if($("textarea[name='memo[subject]']").val().trim() != "" && !memo_content.isEmpty() ){ + if($("textarea[name='memo[subject]']").val().trim() != "" && !memo_content.isEmpty() && first_click){ + first_click = false; memo_content.sync(); $.ajax({ url:'/forums/'+'<%= @forum.id.to_s%>'+'/memos', diff --git a/app/views/forums/show.js.erb b/app/views/forums/show.js.erb index 9e36215ac..48b1474cb 100644 --- a/app/views/forums/show.js.erb +++ b/app/views/forums/show.js.erb @@ -1,2 +1 @@ $("#topics_list").html("<%= escape_javascript(render :partial => 'show_topics',:locals => {:memos=>@memos})%>") -$("#pages").html('<%= pagination_links_full @topic_pages, @topic_count,:per_page_links => false,:remote =>true%>'); \ No newline at end of file diff --git a/app/views/layouts/_user_courses.html.erb b/app/views/layouts/_user_courses.html.erb index 1e0f46926..ff18e68bd 100644 --- a/app/views/layouts/_user_courses.html.erb +++ b/app/views/layouts/_user_courses.html.erb @@ -84,10 +84,10 @@ <% end%> - - - - - - - - - - - - - - -
-
- <%= render :partial => 'organizations/org_logined_header' %> -
- -
- -
-
    - <% @subfield_content.each do |field| %> - <% if is_default_field?(field) %> - <% case field.name %> - <% when 'activity' %> - - <% when 'course' %> - - <% when 'project' %> - - <% end %> - <% else %> - <% if field.field_type == "Post" && field.hide == 0 %> - - <% elsif field.field_type == "Resource" && field.hide == 0 %> - - <% end %> - <% end %> - <% end %> - <% if User.current.admin_of_org?(@organization) %> - - <% end %> -
-
-
-
-<%# 更新访问数,刷新的时候更新访问次数 %> -<% update_visiti_count @organization %> -<%# over %> - -
-
- <% @subfield_content.each do |field| %> - <% if field.status.to_i == 1 %> - <%= render :partial => 'organizations/org_subfield_leftT', :locals => {:field => field} %> - <% elsif field.status.to_i == 2 %> - <%#= render :partial => 'organizations/org_subfield_leftM', :locals => {:field => field} %> -
- <%= render :partial => 'organizations/org_subfield_leftM1', :locals => {:field => field} %> - <% elsif field.status.to_i == 3 %> - <%= render :partial => 'organizations/org_subfield_leftM2', :locals => {:field => field} %> -
-
- <% elsif field.status.to_i == 4 %> - <%= render :partial => 'organizations/org_subfield_leftMD', :locals => {:field => field} %> - <% elsif field.status.to_i == 5 %> - <%= render :partial => 'organizations/org_subfield_leftD', :locals => {:field => field} %> - <% end %> - <% end %> -
- -
- <% @subfield_content.each do |field| %> - <% if field.status.to_i == 6 %> - <%= render :partial => 'organizations/org_subfield_rightT', :locals => {:field => field} %> - <% elsif field.status.to_i == 7 %> - <%= render :partial => 'organizations/org_subfield_rightM', :locals => {:field => field} %> - <% elsif field.status.to_i == 8 %> - <%= render :partial => 'organizations/org_subfield_rightD', :locals => {:field => field} %> - <% end %> - <% end %> -
-
-
- - - - -<%#= call_hook :view_layouts_base_body_bottom %> - - - + + + + + <%= h html_title %> + + + <%= csrf_meta_tag %> + <%= favicon %> + <%= javascript_heads %> + <%= heads_for_theme %> + <%= stylesheet_link_tag 'org2','jquery/jquery-ui-1.9.2' %> + <%= 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 -%> + + + + + + + + + + + + + + + +
+
+ <%= render :partial => 'organizations/org_logined_header' %> +
+ +
+ +
+
    + <% @subfield_content.each do |field| %> + <% if is_default_field?(field) %> + <% case field.name %> + <% when 'activity' %> + + <% when 'course' %> + + <% when 'project' %> + + <% end %> + <% else %> + <% if field.field_type == "Post" && field.hide == 0 %> + + + + <% elsif field.field_type == "Resource" && field.hide == 0 %> + + <% end %> + <% end %> + <% end %> + <% if User.current.admin_of_org?(@organization) %> + + <% end %> +
+
+
+
+<%# 更新访问数,刷新的时候更新访问次数 %> +<% update_visiti_count @organization %> +<%# over %> + +
+
+ <% @subfield_content.each do |field| %> + <% if field.status.to_i == 1 %> + <%= render :partial => 'organizations/org_subfield_leftT', :locals => {:field => field} %> + <% elsif field.status.to_i == 3 %> + <%#= render :partial => 'organizations/org_subfield_leftM', :locals => {:field => field} %> +
+ <%= render :partial => 'organizations/org_subfield_leftM1', :locals => {:field => field} %> + <%= render :partial => 'organizations/org_subfield_leftM2', :locals => {:field => field} %> +
+
+ <% elsif field.status.to_i == 4 %> + <%= render :partial => 'organizations/org_subfield_leftMD', :locals => {:field => field} %> + <% elsif field.status.to_i == 5 %> + <%= render :partial => 'organizations/org_subfield_leftD', :locals => {:field => field} %> + <% end %> + <% end %> +
+ +
+ <% @subfield_content.each do |field| %> + <% if field.status.to_i == 6 %> + <%= render :partial => 'organizations/org_subfield_rightT', :locals => {:field => field} %> + <% elsif field.status.to_i == 7 %> + <%= render :partial => 'organizations/org_subfield_rightM', :locals => {:field => field} %> + <% elsif field.status.to_i == 8 %> + <%= render :partial => 'organizations/org_subfield_rightD', :locals => {:field => field} %> + <% elsif field.status.to_i == 23 %> + <%= render :partial => 'organizations/org_subfield_rightM2', :locals => {:field => field} %> + <% end %> + <% end %> +
+
+
+ + + + +
+ + + +<%#= call_hook :view_layouts_base_body_bottom %> + + + + + + + + diff --git a/app/views/layouts/base_sub_domain.html.erb b/app/views/layouts/base_sub_domain.html.erb new file mode 100644 index 000000000..871e2cdea --- /dev/null +++ b/app/views/layouts/base_sub_domain.html.erb @@ -0,0 +1,191 @@ + + + + + <%= h html_title %> + + + <%= 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 -%> + + + + + + + + + + + + + + + +
+
+
+ <%= render :partial => 'organizations/org_logined_header' %> +
+ +
+ +
+
    + <% @subfield_content.each do |field| %> + <% if is_default_field?(field) %> + <% case field.name %> + <% when 'activity' %> + + <% when 'course' %> + + <% when 'project' %> + + <% end %> + <% else %> + <% if field.field_type == "Post" && field.hide == 0 %> + + + + <% elsif field.field_type == "Resource" && field.hide == 0 %> + + <% end %> + <% end %> + <% end %> + <% if User.current.admin_of_org?(@organization) %> + + <% end %> +
+
+
+
+ banner image + +
+
+
+
+<%# 更新访问数,刷新的时候更新访问次数 %> + <% update_visiti_count @organization %> +<%# over %> + + + + <%= render_flash_messages %> + <%= yield %> + <%= call_hook :view_layouts_base_content %> +
+ + +
+ + +
+ + + + + + + + diff --git a/app/views/layouts/new_base_user.html.erb b/app/views/layouts/new_base_user.html.erb index 313a1e86a..e43aa499f 100644 --- a/app/views/layouts/new_base_user.html.erb +++ b/app/views/layouts/new_base_user.html.erb @@ -226,8 +226,7 @@ end %> - <% courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5) %> - + <% 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 a").order("a desc").limit(5) %>
- <%= render :partial => 'organizations/show_org_document', :locals => {:document => document, :act => OrgActivity.where("org_act_type='OrgDocumentComment'and org_act_id=?", document.id).first, :flag => 0} %> - <% end %> +<%= content_for(:header_tags) do %> + <%= import_ke(enable_at: false, prettify: false, init_activity: true) %> +<% end %> + +<%= render :partial => 'new' %> +<% unless @documents.nil? %> + <% @documents.each do |document| %> + + <%= render :partial => 'organizations/show_org_document', :locals => {:document => document, :act => OrgActivity.where("org_act_type='OrgDocumentComment'and org_act_id=?", document.id).first, :flag => 0} %> + <% end %> <% end %> \ No newline at end of file diff --git a/app/views/org_subfields/create.js.erb b/app/views/org_subfields/create.js.erb index 3e08d9f9e..5cc6d5c91 100644 --- a/app/views/org_subfields/create.js.erb +++ b/app/views/org_subfields/create.js.erb @@ -4,6 +4,7 @@ :locals => {:subfields => @organization.org_subfields.order("priority") }) %>"); $("#sub_field_left_lists").html(""); $("#sub_field_left_lists").html("<%= escape_javascript(render :partial => 'organizations/org_left_subfield_list', :locals => {:organization => @organization}) %>"); + $("#org_excellent_teachers").html("<%= escape_javascript(render :partial => 'organizations/setting_excellent_teachers') %>"); <% end %> $("#subfield_name").val(""); $("#sub_dir").val(""); \ No newline at end of file diff --git a/app/views/org_subfields/destroy.js.erb b/app/views/org_subfields/destroy.js.erb index d069b1cd8..c14eeae8f 100644 --- a/app/views/org_subfields/destroy.js.erb +++ b/app/views/org_subfields/destroy.js.erb @@ -2,4 +2,5 @@ $("#org_subfield_list").html(""); $("#org_subfield_list").html("<%= escape_javascript(render :partial => 'organizations/subfield_list', :locals => {:subfields => @organization.org_subfields.order("priority") }) %>"); $("#sub_field_left_lists").html(""); -$("#sub_field_left_lists").html("<%= escape_javascript(render :partial => 'organizations/org_left_subfield_list', :locals => {:organization => @organization}) %>"); \ No newline at end of file +$("#sub_field_left_lists").html("<%= escape_javascript(render :partial => 'organizations/org_left_subfield_list', :locals => {:organization => @organization}) %>"); +$("#org_excellent_teachers").html("<%= escape_javascript(render :partial => 'organizations/setting_excellent_teachers') %>"); \ No newline at end of file diff --git a/app/views/organizations/_link_subfield_more.html.erb b/app/views/organizations/_link_subfield_more.html.erb new file mode 100644 index 000000000..cb4a82ed1 --- /dev/null +++ b/app/views/organizations/_link_subfield_more.html.erb @@ -0,0 +1,9 @@ +<% if !field.subfield_subdomain_dir.nil? %> + <% if !request.local? and Secdomain.where("sub_type=2 and pid=?", @organization.id).count > 0 and Secdomain.where("sub_type=2 and pid=?", @organization.id).map(&:subname).include?(request.subdomain) %> + <%= link_to "更多", show_subfield_without_id_path(:sub_dir_name => field.subfield_subdomain_dir.name), :class => "more" , :target => "_blank" %> + <% else %> + <%= link_to "更多", show_org_subfield_organization_path(:id => @organization.id, :sub_dir_name => field.subfield_subdomain_dir.name), :class => "more" , :target => "_blank" %> + <% end %> +<% else %> + <%= link_to "更多", organization_path(@organization, :org_subfield_id => field.id), :class => "more" , :target => "_blank" %> +<% end %> \ No newline at end of file diff --git a/app/views/organizations/_org_course_homework.html.erb b/app/views/organizations/_org_course_homework.html.erb index 33e2835dd..b4ca46959 100644 --- a/app/views/organizations/_org_course_homework.html.erb +++ b/app/views/organizations/_org_course_homework.html.erb @@ -140,8 +140,8 @@
<% if activity.student_works.count != 0 %> <% sw_id = "("+activity.student_works.map{|sw| sw.id}.join(",")+")" %> - <% student_work_scores = StudentWorksScore.find_by_sql("select max(created_at) as created_at, student_work_id, user_id from student_works_scores where student_work_id in #{sw_id} group by student_work_id order by max(created_at) desc") %> - <%# student_work_scores = StudentWorksScore.where("student_work_id in #{sw_id}").reorder("created_at desc") %> + <%# student_work_scores = StudentWorksScore.find_by_sql("select max(created_at) as created_at, student_work_id, user_id from student_works_scores where student_work_id in #{sw_id} group by student_work_id order by max(created_at) desc") %> + <% student_work_scores = StudentWorksScore.where("student_work_id in #{sw_id} and score is not null").reorder("created_at desc") %> <% unless student_work_scores.empty? %> <% last_score = student_work_scores.first %>
@@ -159,8 +159,18 @@ <% end %> <% student_works.each_with_index do |sw, i| %>
- <%= link_to image_tag(url_to_avatar(User.find sw.user_id), :width => "40", :height => "40"), student_work_index_url_in_org(activity.id), :alt => "学生头像" %> - + + <% if User.current.member_of_course?(activity.course) || User.current.admin? || activity.is_open == 1 %> + <%= link_to image_tag(url_to_avatar(User.find sw.user_id), :width => "40", :height => "40"), student_work_index_url_in_org(activity.id, '', sw.id), :alt => "学生头像" %> + + <% else %> + <%= image_tag(url_to_avatar(User.find sw.user_id), :width => "40", :height => "40", :title => '该作业的作品暂未公开') %> + + <% end %> <% score = sw.respond_to?("score") ? sw.score : (sw.final_score || 0) - sw.absence_penalty - sw.late_penalty %>

分数:<%=format("%.1f",score.to_i<0 ? 0 : score.to_i) %>分

@@ -182,7 +192,8 @@ <% sort_projects = project_sort_update projects %>
- # <%=time_from_now sort_projects.first.updated_at %><%= link_to User.find(sort_projects.first.user_id).show_name, user_activities_url_in_org(sort_projects.first.user_id), :class => "newsBlue ml5 mr5"%>更新了项目,最近更新: + <% first_pro = project_sort_first(projects).first %> + # <%=time_from_now first_pro.updated_at %><%= link_to User.find(first_pro.user_id).show_name, user_activities_url_in_org(first_pro.user_id), :class => "newsBlue ml5 mr5"%>更新了项目,最近更新:
<% sort_projects.each_with_index do |pro, i| %> @@ -275,7 +286,8 @@ <% count=activity.journals_for_messages.count %>
-
回复 +
回复 + ︿ <%= count>0 ? "(#{count})" : "" %> <% if activity.user == User.current %> @@ -317,23 +329,60 @@ <% else %> <%= link_to comment.try(:user).try(:realname), user_url_in_org(comment.user_id), :class => "newsBlue mr10 f14" %> <% end %> - <%= format_time(comment.created_on) %> - - <% if comment.user == User.current %> - + <%= time_from_now(comment.created_on) %> +
+ <% unless comment.m_parent_id.nil? %> + <% parents_rely = [] %> + <% parents_rely = get_reply_parents parents_rely, comment %> + <% length = parents_rely.length %> +
+ <% if length <= 3 %> + <%=render :partial => 'users/comment_reply', :locals => {:comment => comment.parent} %> <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> +
+
+
+ <%=render :partial => 'users/comment_reply', :locals => {:comment => parents_rely[length - 1]} %> +
+ <%=render :partial => 'users/comment_reply_detail', :locals => {:comment => parents_rely[length - 2]} %> +
+
<%= link_to '点击展开隐藏楼层', show_all_replies_users_path(:comment => comment),:remote=>true %>
+ <%=render :partial => 'users/comment_reply_detail', :locals => {:comment => parents_rely[0]} %> +
<% end %> - - -
+
+ <% end %>
<%= comment.notes.html_safe %>
+
+
+ + + <% if comment.user == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> + <% end %> + + + <%= link_to( + l(:button_reply), + {:controller => 'users' ,:action => 'reply_to', :reply_id => comment.id, :type => 'HomeworkCommon', :is_in_course => -1, :user_activity_id => user_activity_id, :course_activity=>course_activity}, + :remote => true, + :method => 'get', + :title => l(:button_reply)) %> + + + + <% if User.current.admin? ||is_teacher || comment.user == User.current%> + <%= link_to('删除', {:controller => 'words', :action => 'destroy', :object_id => comment, :user_id => comment.user,:is_in_course => -1, :user_activity_id => user_activity_id, :course_activity=>course_activity}, + :remote => true, :confirm => l(:text_are_you_sure), :method => 'delete', :class => "fr mr20", :title => l(:button_delete)) %> + <% end %> + +
+
+
+

diff --git a/app/views/organizations/_org_left_subfield_list.html.erb b/app/views/organizations/_org_left_subfield_list.html.erb index ebab8354c..4340213a4 100644 --- a/app/views/organizations/_org_left_subfield_list.html.erb +++ b/app/views/organizations/_org_left_subfield_list.html.erb @@ -43,6 +43,13 @@ $(this).prev().css("color","#808080"); $(this).css("z-index", "1"); }) + + //二级菜单滑动时箭头方向控制 + $(".homepageLeftMenuMoreIcon").toggle(function(){ + $(this).css("background","url(/images/homepage_icon.png) 100px -624px no-repeat"); + },function(){ + $(this).css("background","url(/images/homepage_icon.png) -74px -240px no-repeat"); + }); }) @@ -83,35 +90,55 @@
<% end %> <% else %> -
- <% if field.field_type == "Post" %> - <% if !field.subfield_subdomain_dir.nil? %> - <% if !request.local? and Secdomain.where("sub_type=2 and pid=?", organization.id).count > 0 and Secdomain.where("sub_type=2 and pid=?", organization.id).map(&:subname).include?(request.subdomain) %> - <%= link_to "#{field.name}", show_subfield_without_id_path(:sub_dir_name => field.subfield_subdomain_dir.name), :class => "homepageMenuText" %> - <% else %> - <%= link_to "#{field.name}", show_org_subfield_organization_path(:id => organization.id, :sub_dir_name => field.subfield_subdomain_dir.name), :class => "homepageMenuText" %> - <% end %> - <% else %> - <%= link_to "#{field.name}", organization_path(organization, :org_subfield_id => field.id), :class => "homepageMenuText" %> - <% end %> - <% if User.current.member_of_org?organization %> - <%=link_to "", new_organization_org_document_comment_path(organization, :field_id => field.id), :method => "get", :class => "homepageMenuSetting fr", :title => "发布帖子"%> +
+ <% if field.field_type == "Post" || field.field_type == "Complex" || field.field_type == "Compstu" || field.field_type == "Comptec" %> +
+ + <% if !field.subfield_subdomain_dir.nil? %> + <% if !request.local? and Secdomain.where("sub_type=2 and pid=?", organization.id).count > 0 and Secdomain.where("sub_type=2 and pid=?", organization.id).map(&:subname).include?(request.subdomain) %> + <%= link_to "#{field.name}", show_subfield_without_id_path(:sub_dir_name => field.subfield_subdomain_dir.name), :class => "homepageMenuText homepageMenuControl hidden", :onclick => "$('#homepageLeftMenuPost').slideToggle();" %> + <% else %> + <%= link_to "#{field.name}", show_org_subfield_organization_path(:id => organization.id, :sub_dir_name => field.subfield_subdomain_dir.name), :class => "homepageMenuText homepageMenuControl hidden", :onclick => "$('#homepageLeftMenuPost').slideToggle();" %> + <% end %> + <% else %> + <% if field.field_type == "Comptec" %> + <%= link_to "#{field.name}", teachers_organization_path(organization, :org_subfield_id => field.id), :class => "homepageMenuText homepageMenuControl hidden", :onclick => "$('#homepageLeftMenuPost').slideToggle();" %> + <% else %> + <%= link_to "#{field.name}", organization_path(organization, :org_subfield_id => field.id), :class => "homepageMenuText homepageMenuControl hidden", :onclick => "$('#homepageLeftMenuPost').slideToggle();" %> + <% end %> + <% end %> + <% if User.current.logged? and User.current.admin_of_org?(organization) && field.field_type != "Comptec" %> + <%=link_to "", new_organization_org_document_comment_path(organization, :field_id => field.id), :method => "get", :class => "homepageMenuSetting fr", :title => "发布帖子" %> + <% end %> +
+ + + <% unless (field.sub_domains.count == 0 || !if_hidden_subdomain(field)) %> +
  • + +
  • <% end %> <% else %> - <% if !field.subfield_subdomain_dir.nil? %> - <% if !request.local? and Secdomain.where("sub_type=2 and pid=?", organization.id).count > 0 and Secdomain.where("sub_type=2 and pid=?", organization.id).map(&:subname).include?(request.subdomain) %> - <%= link_to "#{field.name}", show_subfield_without_id_path(:sub_dir_name => field.subfield_subdomain_dir.name), :class => "homepageMenuText" %> +
    + <% if !field.subfield_subdomain_dir.nil? %> + <% if !request.local? and Secdomain.where("sub_type=2 and pid=?", organization.id).count > 0 and Secdomain.where("sub_type=2 and pid=?", organization.id).map(&:subname).include?(request.subdomain) %> + <%= link_to "#{field.name}", show_subfield_without_id_path(:sub_dir_name => field.subfield_subdomain_dir.name), :class => "homepageMenuText homepageMenuControl hidden" %> + <% else %> + <%= link_to "#{field.name}", show_org_subfield_organization_path(:id => organization.id, :sub_dir_name => field.subfield_subdomain_dir.name), :class => "homepageMenuText homepageMenuControl hidden" %> + <% end %> <% else %> - <%= link_to "#{field.name}", show_org_subfield_organization_path(:id => organization.id, :sub_dir_name => field.subfield_subdomain_dir.name), :class => "homepageMenuText" %> + <%= link_to "#{field.name}", org_subfield_files_path(field), :class => "homepageMenuText homepageMenuControl hidden" %> <% end %> - <% else %> - <%= link_to "#{field.name}", org_subfield_files_path(field), :class => "homepageMenuText" %> - <% end %> - <% if User.current.member_of_org?organization %> - <%= link_to "", subfield_upload_file_org_subfield_files_path(field.id, :in_org => 1),:method => "post", :remote => true, :class => "homepageMenuSetting fr", :title => "上传资源" %> - - <% end %> - + <% if User.current.member_of_org?organization %> + <%= link_to "", subfield_upload_file_org_subfield_files_path(field.id, :in_org => 1),:method => "post", :remote => true, :class => "homepageMenuSetting fr", :title => "上传资源" %> + + <% end %> + +
    <% end %>