diff --git a/Gemfile b/Gemfile index a599613ba..d392c6561 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source 'https://rubygems.org/' +source 'https://ruby.taobao.org/' ### ����ִ��bundle config mirror.https://rubygems.org https://gems.ruby-china.org �л���ruby-chinaԴ unless RUBY_PLATFORM =~ /w32/ diff --git a/app/controllers/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb index d7e38f370..c938a2d4b 100644 --- a/app/controllers/org_document_comments_controller.rb +++ b/app/controllers/org_document_comments_controller.rb @@ -1,6 +1,6 @@ class OrgDocumentCommentsController < ApplicationController before_filter :find_organization, :only => [:new, :create, :show, :index] - before_filter :authorize_allowed, :only => [:create, :add_reply] + before_filter :authorize_allowed, :only => [:create] helper :attachments,:organizations layout 'base_org' @@ -13,6 +13,7 @@ class OrgDocumentCommentsController < ApplicationController @org_document_comment = OrgDocumentComment.new(:organization_id => @organization.id, :creator_id => User.current.id) @org_document_comment.title = params[:org_document_comment][:title] @org_document_comment.content = params[:org_document_comment][:content] + @org_document_comment.status = params[:org_document_comment][:status] == "on" ? 1 : 0 @org_document_comment.save_attachments(params[:attachments]) if params[:field_id] @org_document_comment.org_subfield_id = params[:field_id].to_i diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb index c628b25fc..159648f34 100644 --- a/app/controllers/org_subfields_controller.rb +++ b/app/controllers/org_subfields_controller.rb @@ -6,7 +6,7 @@ class OrgSubfieldsController < ApplicationController if OrgSubfield.where("organization_id=#{params[:organization_id]} and name=?",params[:name]).count == 0 @res = true @organization = Organization.find(params[:organization_id]) - @subfield = OrgSubfield.create(:name => params[:name], :organization_id => params[:organization_id],:priority => @organization.org_subfields.order("priority").last.priority + 1) + @subfield = OrgSubfield.create(:name => params[:name], :organization_id => params[:organization_id], :priority => @organization.org_subfields.order("priority").last.priority + 1) if !params[:sub_dir].blank? sql = "select subfield_subdomain_dirs.* from subfield_subdomain_dirs, org_subfields where subfield_subdomain_dirs.org_subfield_id = org_subfields.id "+ "and org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir]}'" @@ -15,17 +15,31 @@ 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 + # admin配置的类型 + update_status_by_type(@subfield, params[:field_type]) else @res = false end end + # status类型说明,详见SubField + def update_status_by_type subfield, type + case type + when "Resource" + subfield.update_attribute(:status, 6) + when "Comptec" + subfield.update_attribute(:status, 6) + when "Compstu" + subfield.update_attribute(:status, 7) + when "Comppro" + subfield.update_attribute(:status, 5) + when "Compcou" + subfield.update_attribute(:status, 2) + when "Compact" + subfield.update_attribute(:status, 4) + end + end + def show @flag = params[:flag] || false sort = "" diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 3ab62bbea..a0ef84798 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -28,7 +28,8 @@ class OrganizationsController < ApplicationController helper :project_score helper :issues include UsersHelper - before_filter :find_organization, :only => [:show, :members, :apply_subdomain, :select_org_layout, :teachers] + before_filter :find_organization, :only => [:show, :members, :apply_subdomain, :select_org_layout, :teachers, :students, :projects, :courses] + before_filter :allow_as_admin, :only => [:students, :teachers, :projects, :courses, :acts] layout 'base_org' def index @@ -76,22 +77,34 @@ class OrganizationsController < ApplicationController def show # 组织新类型 show_mode:判断标准 1为新类型,0为旧 - if @organization.show_mode.to_i == 1 && params[:org_subfield_id].nil? && params[:list] .nil? + if @organization.switch_type && 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 - @org_banner_attchment = Attachment.find_by_sql("SELECT * from attachments WHERE container_id = #{@organization.id} and container_type = 'Organization' and attachtype = 1 and filename REGEXP '(.jpg|.png|.bmp|.gif|.jpeg)' ORDER BY created_on desc limit 1").first - @subfield_content = @organization.org_subfields.order("priority") - @organization = Organization.find(params[:id]) - 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 - course_ids = (@organization.courses.map(&:id)-shield_course_ids) << 0 - 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 - render :layout => 'base_org2' + 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 + course_ids = (@organization.courses.map(&:id) - shield_course_ids) << 0 + 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 + # 精品课程, 不符合条件的组织则不查询 + if @organization.org_subfields.where(:field_type => "Compcou", :hide => 0).count > 0 + @excellent_courses = Course.find_by_sql("select c.*, (select count(*) from course_activities where course_activities.course_id = c.id) as course_count + from courses c where c.is_delete =0 and c.is_public =1 and is_excellent =1 order by course_count desc limit 5;") + end + # 热门项目 + if @organization.org_subfields.where(:field_type => "Comppro", :hide => 0).count > 0 + # @excellent_projects = Project.where(:is_public => true, :status => true, :hot => true).order("project_score") + @excellent_projects = Project.find_by_sql("select p.*, (select count(*) from forge_activities where forge_activities.project_id = p.id) as project_count + from projects p where p.status =1 and p.is_public =1 and hot =1 order by project_count desc limit 5;") + end + # 最新动态, 来自我关联的项目和课程 + if @organization.org_subfields.where(:field_type => "Compact", :hide => 0).count > 0 + @acts = UserActivity.find_by_sql("SELECT * FROM `user_activities` where act_type in ('HomeworkCommon', 'News', 'Message', 'Issue') and + ((container_type = 'Course' and container_id in (#{course_ids.join(',')})) or (container_type = 'Project' and container_id in (#{project_ids.join(',')}))) + order by created_at desc limit 6;") + end + render :layout => 'base_org_custom' else render_403 end @@ -159,22 +172,12 @@ class OrganizationsController < ApplicationController end def teachers - unless @organization.allow_set_teachers - render_403 - return - end q = params[:search].nil? ? "" : "#{params[:search].strip}" @field = params[:org_subfield_id].nil? ? OrgSubfield.where("organization_id =? and field_type =?", params[:id].to_i, "Comptec").first : 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") @@ -192,6 +195,73 @@ class OrganizationsController < ApplicationController end end + def students + q = params[:search].nil? ? "" : "#{params[:search].strip}" + @field = params[:org_subfield_id].nil? ? OrgSubfield.where("organization_id =? and field_type =?", params[:id].to_i, "Compstu").first : OrgSubfield.find(params[:org_subfield_id]) + @type = params[:type] + if @type == "courses" || @type.nil? + @org_students = User.find_by_sql("select u.*, ue.student_id, 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= 1 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc") + elsif @type == "famous" + @org_students = User.find_by_sql("select u.*, ue.student_id, 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= 1 and u.excellent_student =1 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc") + end + limit = 10 + # @is_remote = true + @students_count = @org_students.count + @atta_pages = Paginator.new @students_count, limit, params['page'] || 1 + @offset ||= @atta_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @org_students = paginateHelper @org_students, limit + respond_to do |format| + format.html + format.js + end + end + + def atta_page_public container + limit = 10 + @containers_count = container.count + @atta_pages = Paginator.new @containers_count, limit, params['page'] || 1 + @offset ||= @atta_pages.offset + @containers = paginateHelper container, limit + respond_to do |format| + format.html + format.js + end + end + + def projects + q = params[:search].nil? ? "" : "#{params[:search].strip}" + @field = params[:org_subfield_id].nil? ? OrgSubfield.where("organization_id =? and field_type =?", params[:id].to_i, "Comppro").first : OrgSubfield.find(params[:org_subfield_id]) + @type = params[:type] + if @type.nil? + @containers = Project.find_by_sql("select p.*, (select count(*) from forge_activities where forge_activities.project_id = p.id) as project_count + from projects p where p.status =1 and p.is_public =1 and name like '%#{q}%' order by project_count desc;") + elsif @type == "famous" + @containers = Project.find_by_sql("select p.*, (select count(*) from forge_activities where forge_activities.project_id = p.id) as project_count + from projects p where p.status =1 and p.is_public =1 and hot =1 and name like '%#{q}%' order by project_count desc;") + end + atta_page_public @containers + end + + def courses + q = params[:search].nil? ? "" : "#{params[:search].strip}" + @field = params[:org_subfield_id].nil? ? OrgSubfield.where("organization_id =? and field_type =?", params[:id].to_i, "Compstu").first : OrgSubfield.find(params[:org_subfield_id]) + @type = params[:type] + if @type.nil? + @containers = Course.find_by_sql("select c.*, (select count(*) from course_activities where course_activities.course_id = c.id) as course_count + from courses c where c.is_delete =0 and c.is_public =1 and name like '%#{q}%' order by course_count desc;") + elsif @type == "famous" + @containers = Course.find_by_sql("select c.*, (select count(*) from course_activities where course_activities.course_id = c.id) as course_count + from courses c where c.is_delete =0 and c.is_public =1 and is_excellent = 1 and name like '%#{q}%' order by course_count desc;") + end + atta_page_public @containers + end + + def acts + end + def searchmember_by_name members, name #searchPeopleByRoles(project, StudentRoles) mems = [] @@ -322,6 +392,13 @@ class OrganizationsController < ApplicationController @organization = Organization.find(params[:id]) end + def allow_as_admin + unless User.current.admin? + render_403 + return + end + end + def setting @organization = Organization.find(params[:id]) @@ -471,6 +548,18 @@ class OrganizationsController < ApplicationController end end + def update_field_by_admin + @type = params[:type] + @status = params[:status] + if @type == "project" + @container = Project.find(params[:container]) + @status == "reset" ? @container.update_column(:hot, 0) : @container.update_column(:hot, 1) + else + @container = Course.find(params[:container]) + @status == "reset" ? @container.update_column(:is_excellent, 0) : @container.update_column(:is_excellent, 1) + end + end + # 设置为名师 def set_excellent_teacher @ex_teacher = User.find(params[:user]) @@ -483,6 +572,16 @@ class OrganizationsController < ApplicationController @ex_teacher.update_column(:excellent_teacher, 0) end + def set_excellent_student + @ex_student = User.find(params[:user]) + @ex_student.update_column(:excellent_student, 1) + end + + def reset_excellent_student + @ex_student = User.find(params[:user]) + @ex_student.update_column(:excellent_student, 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/sub_document_comments_controller.rb b/app/controllers/sub_document_comments_controller.rb index 80c14f004..d6b335006 100644 --- a/app/controllers/sub_document_comments_controller.rb +++ b/app/controllers/sub_document_comments_controller.rb @@ -1,7 +1,7 @@ class SubDocumentCommentsController < ApplicationController before_filter :find_subdomain_and_subfield, :only => [:new, :create, :show, :index, :destroy, :edit] before_filter :find_subfield_content, :only => [:show, :index] - before_filter :authorize_allowed, :only => [:create, :add_reply] + before_filter :authorize_allowed, :only => [:create] helper :attachments,:organizations layout 'base_sub_domain' diff --git a/app/controllers/sub_domains_controller.rb b/app/controllers/sub_domains_controller.rb index e32935789..438b67eec 100644 --- a/app/controllers/sub_domains_controller.rb +++ b/app/controllers/sub_domains_controller.rb @@ -18,6 +18,9 @@ class SubDomainsController < ApplicationController else @res = false end + respond_to do |format| + format.js + end end def update diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 009d5c4d6..88a524d1e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -123,6 +123,20 @@ class UsersController < ApplicationController end + #未读消息弹窗 + def user_messages_unviewed + @message_alls = [] + messages = MessageAll.where("user_id =?", User.current.id).includes(:message).order("created_at desc") + onclick_time = User.current.onclick_time.onclick_time + messages.each do |message_all| + # 未读的消息存放在数组 + if (message_all.message_type != "SystemMessage"&& !message_all.message.nil? && message_all.message.viewed == 0) || (message_all.message_type == "SystemMessage"&& !message_all.message.nil? && message_all.message.created_at > onclick_time) + @message_alls << message_all.message + break if @message_alls.length == 5 + end + end + end + # 用户消息 # 说明: homework 发布作业;message:讨论区; news:新闻; poll:问卷;works_reviewers:作品评阅;works_reply:作品回复,exercise:课程测验 # issue:问题;journal:缺陷状态更新; forum:公共贴吧: user_feedback: 用户留言; new_reply:新闻回复(comment) @@ -443,12 +457,7 @@ class UsersController < ApplicationController # 资源分享请求弹框 def apply_resource - if User.current.logged? - @attachment = Attachment.find params[:attachment_id] - @state = 2 - else - @state = 1 - end + @attachment = Attachment.find params[:attachment_id] respond_to do |format| format.js end @@ -2036,7 +2045,7 @@ class UsersController < ApplicationController @score = @b_sort == "desc" ? "asc" : "desc" user_project_ids = User.current.projects.map {|p| p.id} user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 - if(params[:type].blank? || params[:type] == "1") # 我的资源 + if(params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == "2" @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) @@ -2050,7 +2059,7 @@ class UsersController < ApplicationController # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) end - elsif params[:type] == "6" # 公共资源 + elsif (params[:type].blank? || params[:type] == "6") # 公共资源 if params[:status] == "2" @attachments = get_course_resources_public( user_course_ids, @order, @score) elsif params[:status] == "3" @@ -2190,7 +2199,7 @@ class UsersController < ApplicationController @score = @b_sort == "desc" ? "asc" : "desc" user_project_ids = User.current.projects.map {|p| p.id} user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 - if(params[:type].blank? || params[:type] == "1") # 我的资源 + if(params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == "2" @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) @@ -2204,7 +2213,7 @@ class UsersController < ApplicationController # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) end - elsif params[:type] == "6" # 公共资源 + elsif (params[:type].blank? || params[:type] == "6") # 公共资源 if params[:status] == "2" @attachments = get_course_resources_public( user_course_ids, @order, @score) elsif params[:status] == "3" @@ -2331,7 +2340,7 @@ class UsersController < ApplicationController @score = @b_sort == "desc" ? "asc" : "desc" user_project_ids = User.current.projects.map {|p| p.id} user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 - if(params[:type].blank? || params[:type] == "1") # 我的资源 + if(params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == "2" @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) @@ -2345,7 +2354,7 @@ class UsersController < ApplicationController # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) end - elsif params[:type] == "6" # 公共资源 + elsif (params[:type].blank? || params[:type] == "6") # 公共资源 if params[:status] == "2" @attachments = get_course_resources_public( user_course_ids, @order, @score) elsif params[:status] == "3" diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index ef59e0ed4..3ccdc3257 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -121,7 +121,7 @@ class WechatsController < ActionController::Base on :fallback, respond: 'fallback message' on :click, with: 'FEEDBACK' do |request, key| - request.reply.text "如有反馈问题,请直接切入至输入框,发微信给我们即可" + request.reply.text "如有反馈问题,请直接切换至输入框,发微信给我们即可" end on :click, with: 'MY_NEWS' do |request, key| diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 691c2b0ad..3aa7d8a4a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -70,7 +70,6 @@ module ApplicationHelper attach = Attachment.find(attachment_id) # 条件取否,result结果为true则不能下载 result = attach.is_public == 0 && attach.author != User.current && !attach.get_apply_resource_status(attach.id, User.current.id) && !attach_show_allow(attach) - return result end # Time 2015-03-24 15:27:29 @@ -3104,9 +3103,10 @@ def named_attachment_url_without_domain(id, filename, option={}) attachment_id = (Attachment === id ? id.id : id) Setting.protocol + "://" + Setting.host_name + "/attachments/" + attachment_id.to_s + "/" + filename end + #判断是否为默认的组织栏目 def is_default_field? field - (field.name == 'activity' || field.name == 'course' || field.name == 'project') && field.field_type == 'default' + (field.name == 'activity' || field.name == 'course' || field.name == 'project' ) && field.field_type == 'default' end def host_with_protocol diff --git a/app/helpers/organizations_helper.rb b/app/helpers/organizations_helper.rb index cba4fa210..fa0d33f6e 100644 --- a/app/helpers/organizations_helper.rb +++ b/app/helpers/organizations_helper.rb @@ -42,11 +42,15 @@ module OrganizationsHelper Attachment.find_by_sql("SELECT * FROM `attachments` where container_id =#{field_id} and container_type = 'OrgSubfield' and is_public =1 order by created_on limit 6;") end + # 获取两种类型的隐藏状态,数量大于0说明是可见 + def double_field_show org + OrgSubfield.find_by_sql("SELECT * FROM `org_subfields` where organization_id = #{org.id} and (field_type = 'Compstu' or field_type = 'Comptec') and hide = 0;").count + end + def get_attach_org2(field) org_attachments = field.attachments - attachments = User.current.admin? ? org_attachments : visable_attachemnts(org_attachments) - return attachments.sort_by{|x| x.created_on}.reverse.first(6) - # Attachment.find_by_sql("SELECT * FROM `attachments` where container_id =#{field_id} and container_type = 'OrgSubfield' and is_public =1 order by created_on limit 6;") + attachments = User.current.admin? ? org_attachments.first(5) : visable_attachemnts(org_attachments).first(5) + attachments.sort_by{|x| x.created_on}.reverse end # 从内容中获取路径 @@ -59,6 +63,58 @@ module OrganizationsHelper end end + def org_user_by_type obj + case obj.act_type + when "Message" + user = obj.act.author + when "News" + user = obj.act.author + when "HomeworkCommon" + user = obj.act.user + when "Issue" + user = obj.act.author + end + end + + def org_title_by_type obj + case obj.act_type + when "Message" + user = obj.act.parent_id.nil? ? obj.act.subject : obj.act.parent.subject + when "News" + user = obj.act.title + when "HomeworkCommon" + user = obj.act.name + when "Issue" + user = obj.act.subject + end + end + + def org_content_by_type obj + case obj.act_type + when "Message" + user = obj.act.parent_id.nil? ? obj.act.content : obj.act.parent.content + when "News" + user = obj.act.description + when "HomeworkCommon" + user = obj.act.description + when "Issue" + user = obj.act.description + end + end + + def org_time_by_type obj + case obj.act_type + when "Message" + time = obj.act.updated_on + when "News" + user = obj.act.created_on + when "HomeworkCommon" + user = obj.act.updated_at + when "Issue" + user = obj.act.updated_on + end + end + #排列下拉框 def subfield_status_option type = [] @@ -66,34 +122,14 @@ module OrganizationsHelper option1 << "左一" option1 << "1" type << option1 - # option2 = [] - # option2 << "中一" - # option2 << "2" - # type << option2 + option2 = [] + option2 << "左二" + option2 << "2" + type << option2 option3 = [] - 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 @@ -104,18 +140,22 @@ module OrganizationsHelper option1 << "左一" option1 << "1" type << option1 + option2 = [] + option2 << "左二" + option2 << "2" + type << option2 option3 = [] - option3 << "左二" - option3 << "3" + option3 << "左三" + option3 << "2" type << option3 option4 = [] - option4 << "左三" - option4 << "4" + option4 << "右一" + option4 << "3" type << option4 - option6 = [] - option6 << "右一" - option6 << "6" - type << option6 + option5 = [] + option5 << "右二" + option5 << "5" + type << option5 type end @@ -128,30 +168,36 @@ module OrganizationsHelper when 3 resulet = "左二" when 4 - resulet = "左三" - when 5 - resulet = "左四" - when 6 resulet = "右一" - when 7 + when 5 resulet = "右二" - when 8 + when 6 resulet = "右三" end end + # 系统栏目只有管理员才能看到 + def subfield_to_addmin?(org) + if User.current.admin? + @organization.org_subfields.order("priority") + else + @organization.org_subfields.select { |os| (os.field_type != "Comptec" && os.field_type != "Compstu" && os.field_type != "Comppro" && os.field_type != "Compcou" && os.field_type != "Compact") }.sort_by {|os| os.priority} + 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 allow_to_create?(org, type) + !org_subfield_had_created?(org, type) && User.current.admin? 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) @@ -166,9 +212,20 @@ module OrganizationsHelper result = "教师" when "Complex" result = "综合" + when "Compcou" + result = "课程" + when "Comppro" + result = "项目" + when "Compact" + result = "动态" end end + # 获取最新动态 + # def get_latest_acts + # acts = UserActivity.find_by_sql("SELECT * FROM `user_activities` where act_type in ('HomeworkCommon', 'news', 'message', 'Issue') and (container_type = 'Course' or container_type = 'Project') order by created_at limit 10;") + # end + def org_teacher_resource_count user results = Attachment.find_by_sql("SELECT * FROM attachments where author_id = #{user.id};").count end @@ -187,4 +244,33 @@ module OrganizationsHelper 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 + def excellent_students + 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 = 1 and u.excellent_student = 1 order by course_count desc").first(5) + end + + def excellent_teachers_hide? org + org.org_subfields.where(:field_type => "Comptec").first.hide + end + + def excellent_students_hide? org + org.org_subfields.where(:field_type => "Compstu").first.hide + end + + #当前学期(2015春季学期) + def current_time_and_term course + str = "" + term = cur_course_term + if (course.time == course.end_time && course.term == course.end_term) || (course.end_term.nil? && course.end_time.nil?) || course.time > Time.now.year + str = course.time.to_s + course.term.to_s + elsif course.time == Time.now.year && set_term_value(cur_course_term) <= set_term_value(course.term) + str = course.time.to_s + course.term.to_s + elsif course.end_time < Time.now.year || (course.end_time == Time.now.year && set_term_value(cur_course_term) >= set_term_value(course.term)) + str = course.end_time.to_s + course.end_term.to_s + else + str = Time.now.year.to_s + cur_course_term.to_s + end + str + end + end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 8f9ee2d85..aa4ef8670 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -143,7 +143,7 @@ class Attachment < ActiveRecord::Base def get_apply_resource_status attachment_id, author_id status = ApplyResource.where("attachment_id =? and user_id =?", attachment_id, author_id).first.try(:status) - status == 2 ? true :false + status == 2 end # add by nwb diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index 255410a89..05ae02fe2 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -21,7 +21,7 @@ class BlogComment < ActiveRecord::Base after_save :add_user_activity after_update :update_activity - after_create :update_parent_time, :blog_wechat_message + after_create :update_parent_time before_destroy :destroy_user_activity scope :like, lambda {|arg| diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 325b599e3..a915b1545 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -30,7 +30,7 @@ class HomeworkCommon < ActiveRecord::Base :author => :author, :url => Proc.new {|o| {:controller => 'student_work', :action => 'index', :homework => o.id}} after_create :act_as_activity, :send_mail,:act_as_course_message - after_update :update_activity, :wechat_message + after_update :update_activity after_save :act_as_course_activity after_destroy :delete_kindeditor_assets diff --git a/app/models/journal.rb b/app/models/journal.rb index 6d59c7414..bea273a41 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -55,7 +55,6 @@ class Journal < ActiveRecord::Base # fq after_save :act_as_activity,:be_user_score, :act_as_forge_message, act_as_at_message(:notes, :user_id) - after_create :issue_wechat_message # end #after_destroy :down_user_score #before_save :be_user_score diff --git a/app/models/org_document_comment.rb b/app/models/org_document_comment.rb index 5aa3c1dab..dd070c825 100644 --- a/app/models/org_document_comment.rb +++ b/app/models/org_document_comment.rb @@ -1,5 +1,6 @@ class OrgDocumentComment < ActiveRecord::Base - attr_accessible :content, :creator_id, :organization_id, :parent_id, :reply_id, :title,:sticky,:locked + # status: 1 模式二中置顶 0:模式二中正常显示 + attr_accessible :content, :creator_id, :organization_id, :parent_id, :reply_id, :title, :sticky, :locked, :status include Redmine::SafeAttributes include ApplicationHelper belongs_to :organization diff --git a/app/models/org_subfield.rb b/app/models/org_subfield.rb index 1151426e3..32212a0e8 100644 --- a/app/models/org_subfield.rb +++ b/app/models/org_subfield.rb @@ -11,6 +11,8 @@ class OrgSubfield < ActiveRecord::Base acts_as_attachable after_create :create_board_sync after_destroy :update_priority + # status 为栏目定制决定参数,1 左一 2 左二 3 左三 4 右一 5 右二 6 右三 默认的 7 学霸 8 热门项目 9 精品课程 10 最新动态 + # 创建资源栏目讨论区 def create_board_sync @board = self.boards.build diff --git a/app/models/organization.rb b/app/models/organization.rb index c35d0591d..50f62ea11 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -18,17 +18,17 @@ class Organization < ActiveRecord::Base end def add_default_subfields - OrgSubfield.create(:organization_id => self.id, :name => 'activity', :field_type => 'default', :priority => 1) - 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) + OrgSubfield.create(:organization_id => self.id, :name => 'activity', :field_type => 'default', :priority => 1, :status => 0) + OrgSubfield.create(:organization_id => self.id, :name => 'course', :field_type => 'default', :priority => 2, :status => 2) + OrgSubfield.create(:organization_id => self.id, :name => 'project', :field_type => 'default', :priority => 3, :status => 2) end def switch_type - self.show_mode.to_i == 1 ? true : false + self.show_mode.to_i == 1 end def allow_set_teachers - self.allow_teacher.to_i == 1 ? true : false + self.allow_teacher.to_i == 1 end def secdomain_name diff --git a/app/views/layouts/_base_footer_public.html.erb b/app/views/layouts/_base_footer_public.html.erb index eb2e83ba2..7c5ab571e 100644 --- a/app/views/layouts/_base_footer_public.html.erb +++ b/app/views/layouts/_base_footer_public.html.erb @@ -4,7 +4,7 @@