diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb index 01a36d5b9..496c3aa92 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,15 +15,29 @@ class OrgSubfieldsController < ApplicationController end end @subfield.update_attributes(:field_type => params[:field_type]) - # 如果栏目是教师或学生,不参入类型的配置,默认定义为右三模式 - if params[:field_type] == "Comptec" || params[:field_type] == "Compstu" - @subfield.update_attribute(:status, 6) - 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 "Comptec" + subfield.update_attribute(:status, 6) + when "Compstu" + subfield.update_attribute(:status, 7) + when "Comppro" + subfield.update_attribute(:status, 8) + when "Compcou" + subfield.update_attribute(:status, 9) + when "Compact" + subfield.update_attribute(:status, 10) + end + end + def show @flag = params[:flag] || false sort = "" diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index fc0a8b35e..1b328ad7e 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, :students] + 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 @@ -159,10 +160,6 @@ class OrganizationsController < ApplicationController end def teachers - unless User.current.admin? - 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] @@ -187,10 +184,6 @@ class OrganizationsController < ApplicationController end def students - unless User.current.admin? - 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, "Compstu").first : OrgSubfield.find(params[:org_subfield_id]) @type = params[:type] @@ -214,6 +207,56 @@ class OrganizationsController < ApplicationController 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 * FROM `projects` where status = 1 and is_public = 1 and name like '%#{q}%' order by updated_on desc;") + elsif @type == "famous" + @containers = Project.find_by_sql("SELECT * FROM `projects` where status =1 and is_public = 1 and hot = 1 and name like '%#{q}%' order by updated_on 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 * FROM `courses` where is_delete = 0 and is_public = 1 and name like '%#{q}%' order by updated_at desc;") + elsif @type == "famous" + @containers = Course.find_by_sql("SELECT * FROM `courses` where is_delete = 0 and is_public = 1 and hot = 1 and name like '%#{q}%' order by updated_at desc;") + end + atta_page_public @containers + end + + def acts + 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 + atta_page_public container @containers + end + def searchmember_by_name members, name #searchPeopleByRoles(project, StudentRoles) mems = [] @@ -344,6 +387,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]) diff --git a/app/helpers/organizations_helper.rb b/app/helpers/organizations_helper.rb index 437014528..8e75ec5d1 100644 --- a/app/helpers/organizations_helper.rb +++ b/app/helpers/organizations_helper.rb @@ -175,6 +175,11 @@ module OrganizationsHelper 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 diff --git a/app/models/org_subfield.rb b/app/models/org_subfield.rb index 76d472ad9..32212a0e8 100644 --- a/app/models/org_subfield.rb +++ b/app/models/org_subfield.rb @@ -11,7 +11,7 @@ class OrgSubfield < ActiveRecord::Base acts_as_attachable after_create :create_board_sync after_destroy :update_priority - # status 为栏目定制决定参数,1 左一 2 左二 3 左三 4 右一 5 右二 6 右三 + # status 为栏目定制决定参数,1 左一 2 左二 3 左三 4 右一 5 右二 6 右三 默认的 7 学霸 8 热门项目 9 精品课程 10 最新动态 # 创建资源栏目讨论区 def create_board_sync diff --git a/app/views/organizations/_org_container.html.erb b/app/views/organizations/_org_container.html.erb new file mode 100644 index 000000000..42c216879 --- /dev/null +++ b/app/views/organizations/_org_container.html.erb @@ -0,0 +1,39 @@ +<% containers.each do |container| %> +