超级管理员的组织可关联所有公开课程和项目

This commit is contained in:
cxt 2016-04-14 12:30:33 +08:00
parent 5e1284605f
commit 19861ba8c6
3 changed files with 15 additions and 5 deletions

View File

@ -352,8 +352,13 @@ class OrganizationsController < ApplicationController
if !params[:name].nil? if !params[:name].nil?
condition = "%#{params[:name].strip}%".gsub(" ","") condition = "%#{params[:name].strip}%".gsub(" ","")
end end
sql = "select courses.* from courses inner join members on courses.id = members.course_id where members.user_id = #{User.current.id} and courses.is_public = 1 and courses.name like '#{condition}'"+ if User.current.admin?
"and courses.id not in (select distinct org_courses.course_id from org_courses where org_courses.organization_id = #{@organization.id}) and courses.is_delete=0" sql = "select courses.* from courses where courses.is_public = 1 and courses.name like '#{condition}'"+
"and courses.id not in (select distinct org_courses.course_id from org_courses where org_courses.organization_id = #{@organization.id}) and courses.is_delete=0"
else
sql = "select courses.* from courses inner join members on courses.id = members.course_id where members.user_id = #{User.current.id} and courses.is_public = 1 and courses.name like '#{condition}'"+
"and courses.id not in (select distinct org_courses.course_id from org_courses where org_courses.organization_id = #{@organization.id}) and courses.is_delete=0"
end
#user_courses = Course.find_by_sql(sql) #user_courses = Course.find_by_sql(sql)
@courses = Course.find_by_sql(sql) @courses = Course.find_by_sql(sql)
# @added_course_ids = @organization.courses.map(&:id) # @added_course_ids = @organization.courses.map(&:id)
@ -396,8 +401,13 @@ class OrganizationsController < ApplicationController
if !params[:name].nil? if !params[:name].nil?
condition = "%#{params[:name].strip}%".gsub(" ","") condition = "%#{params[:name].strip}%".gsub(" ","")
end end
sql = "select projects.* from projects inner join members on projects.id = members.project_id where members.user_id = #{User.current.id} and projects.status != 9 and projects.is_public = 1 and projects.name like '#{condition}'" + if User.current.admin?
sql = "select projects.* from projects where projects.status != 9 and projects.is_public = 1 and projects.name like '#{condition}'" +
" and projects.id not in (select org_projects.project_id from org_projects where organization_id = #{@organization.id}) and status=1" " and projects.id not in (select org_projects.project_id from org_projects where organization_id = #{@organization.id}) and status=1"
else
sql = "select projects.* from projects inner join members on projects.id = members.project_id where members.user_id = #{User.current.id} and projects.status != 9 and projects.is_public = 1 and projects.name like '#{condition}'" +
" and projects.id not in (select org_projects.project_id from org_projects where organization_id = #{@organization.id}) and status=1"
end
#user_projects = Course.find_by_sql(sql) #user_projects = Course.find_by_sql(sql)
@projects = Course.find_by_sql(sql) @projects = Course.find_by_sql(sql)
# @added_course_ids = @organization.projects.map(&:id) # @added_course_ids = @organization.projects.map(&:id)

View File

@ -29,7 +29,7 @@
<div class="fl"> <div class="fl">
<%=form_tag url_for(:controller => 'organizations', :action => 'join_courses', :organization_id => organization_id),:method => 'post', :id => 'join_courses_form', :remote => true,:class=>"resourcesSearchBox" do %> <%=form_tag url_for(:controller => 'organizations', :action => 'join_courses', :organization_id => organization_id),:method => 'post', :id => 'join_courses_form', :remote => true,:class=>"resourcesSearchBox" do %>
<input type="text" name="courses" placeholder="搜索您已加入的课程的名称" class="searchCourse" /> <input type="text" name="courses" placeholder="搜索您已加入的课程的名称" class="searchCourse" />
<div id="search_courses_result_list" class="mb8"></div> <div id="search_courses_result_list" class="mb8 maxHeight100" style="overflow:auto;"></div>
<div class="courseSendSubmit"> <div class="courseSendSubmit">
<a href="javascript:void(0);" onclick="org_join_courses(<%= organization_id %>);" class="sendSourceText">关联</a> <a href="javascript:void(0);" onclick="org_join_courses(<%= organization_id %>);" class="sendSourceText">关联</a>
</div> </div>

View File

@ -29,7 +29,7 @@
<div class="fl"> <div class="fl">
<%=form_tag url_for(:controller => 'organizations', :action => 'join_projects', :organization_id => organization_id),:method => 'post', :id => 'join_projects_form', :remote => true,:class=>"resourcesSearchBox" do %> <%=form_tag url_for(:controller => 'organizations', :action => 'join_projects', :organization_id => organization_id),:method => 'post', :id => 'join_projects_form', :remote => true,:class=>"resourcesSearchBox" do %>
<input type="text" name="projects" placeholder="搜索您已加入的项目的名称" class="searchCourse" /> <input type="text" name="projects" placeholder="搜索您已加入的项目的名称" class="searchCourse" />
<div id="search_projects_result_list" class="mb8 maxHeight100"></div> <div id="search_projects_result_list" class="mb8 maxHeight100" style="overflow:auto;"></div>
<div class="courseSendSubmit"> <div class="courseSendSubmit">
<a href="javascript:void(0);" onclick="org_join_projects(<%= organization_id %>);" class="sendSourceText">关联</a> <a href="javascript:void(0);" onclick="org_join_projects(<%= organization_id %>);" class="sendSourceText">关联</a>
</div> </div>