alan 11 years ago
commit 7696e34ecf

@ -101,9 +101,6 @@ class HomeworkAttachController < ApplicationController
:project_id => project_id :project_id => project_id
} }
#@homework_list = @bid.homeworks
@homework = HomeworkAttach.new(options) @homework = HomeworkAttach.new(options)
@homework.save_attachments(params[:attachments]) @homework.save_attachments(params[:attachments])
render_attachment_warning_if_needed(@homework) render_attachment_warning_if_needed(@homework)
@ -126,18 +123,8 @@ class HomeworkAttachController < ApplicationController
def new def new
@bid = Bid.find(params[:id]) @bid = Bid.find(params[:id])
if User.current.admin? || User.current.member_of_course?(@bid.courses.first) #nwb if User.current.admin? || User.current.member_of_course?(@bid.courses.first)
#该课程的学生的集合(新建不实现功能:添加成员)
#@members = @bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and user_id <> #{User.current.id}", {:role_id => [5, 10]})
#@members = paginateHelper @members,10
#@all_user = []
#@bid.courses.first.members.each do |member|
# @all_user << member.user
#end
@homework = HomeworkAttach.new @homework = HomeworkAttach.new
#@homework_user = members_for_homework(@homework) + User.current
#@members = @all_user - @homework_user
respond_to do |format| respond_to do |format|
format.html # new.html.erb format.html # new.html.erb
format.json { render json: @homework } format.json { render json: @homework }
@ -171,7 +158,6 @@ class HomeworkAttachController < ApplicationController
#users该作业所有成员 #users该作业所有成员
#q:模糊匹配的用户的昵称 #q:模糊匹配的用户的昵称
def members_for_homework homework,users,q def members_for_homework homework,users,q
#homework.bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and user_id not in (:users)", {:role_id => [5, 10],:users => users}).joins(:user).where("users.login like '%#{q}%'")
unpartin_users = homework.bid.courses.first.members.where("user_id not in (:users)", {:users => users}).joins(:user).where("users.login like '%#{q}%'") unpartin_users = homework.bid.courses.first.members.where("user_id not in (:users)", {:users => users}).joins(:user).where("users.login like '%#{q}%'")
canpartin_users = [] canpartin_users = []
unpartin_users.each do |m| unpartin_users.each do |m|
@ -183,9 +169,7 @@ class HomeworkAttachController < ApplicationController
end end
def edit def edit
#@homework = HomeworkAttach.find(params[:id])
if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first) if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
#@members = @homework.bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id)", {:role_id => [5, 10]})
get_homework_member @homework get_homework_member @homework
else else
render_403 :message => :notice_not_authorized render_403 :message => :notice_not_authorized
@ -226,7 +210,6 @@ class HomeworkAttachController < ApplicationController
end end
def destroy def destroy
#@homework = HomeworkAttach.find(params[:id])
if User.current.admin? || User.current == @homework.user if User.current.admin? || User.current == @homework.user
if @homework.destroy if @homework.destroy
respond_to do |format| respond_to do |format|
@ -242,7 +225,6 @@ class HomeworkAttachController < ApplicationController
#显示作业信息 #显示作业信息
def show def show
#@homework = HomeworkAttach.find(params[:id])
if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first) if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
# 打分统计 # 打分统计
stars_reates = @homework. stars_reates = @homework.
@ -279,13 +261,6 @@ class HomeworkAttachController < ApplicationController
#删除留言 #删除留言
def destroy_jour def destroy_jour
@journal_destroyed = JournalsForMessage.delete_message(params[:object_id]) @journal_destroyed = JournalsForMessage.delete_message(params[:object_id])
#@homework = HomeworkAttach.find(params[:id])
#@jours = @homework.journals_for_messages.order("created_on DESC")
#@limit = 10
#@feedback_count = @jours.count
#@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
#@offset ||= @feedback_pages.offset
#@jour = @jours[@offset, @limit]
respond_to do |format| respond_to do |format|
format.js format.js
end end
@ -322,14 +297,6 @@ class HomeworkAttachController < ApplicationController
#获取指定作业的平均得分 #获取指定作业的平均得分
def score def score
#stars_reates = @homework.rates(:quality)
#percent = 0
#stars_reates.each do |star_reates|
# percent = percent + star_reates.stars
#end
#stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count
#result = percent * 1.0 / stars_reates_count
#result
end end
#添加回复 #添加回复

@ -38,41 +38,24 @@ class TagsController < ApplicationController
@obj_id = params[:obj_id] @obj_id = params[:obj_id]
@obj_flag = params[:object_flag] @obj_flag = params[:object_flag]
@selected_tags = Array.new @selected_tags = Array.new
@selected_tag_ids = Array.new
@selected_tag_objs = Array.new
@related_tags = nil @related_tags = nil
@related_tag_ids = Array.new
@related_tag_objs = Array.new if params[:q]
if params[:q] @selected_tags << params[:q]
@tag = ActsAsTaggableOn::Tag.find(params[:q])
@selected_tags << @tag.name
@selected_tag_ids << @tag.id.to_s
@selected_tag_objs << @tag
else else
@do_what = params[:do_what] @do_what = params[:do_what]
@tag = ActsAsTaggableOn::Tag.find(params[:tag]) @tag = params[:tag]
#@selected_tags = params[:current_selected_tags] @selected_tags = params[:current_selected_tags]
@selected_tag_ids = params[:current_selected_tags] @selected_tags = @selected_tags.nil? ? Array.new : @selected_tags
@selected_tag_ids = @selected_tag_ids.nil? ? Array.new : @selected_tag_ids
@selected_tag_ids.each do |t|
ta = ActsAsTaggableOn::Tag.find(t)
@selected_tags << ta.name
@selected_tag_objs << ta
end
#@selected_tags = @selected_tags.nil? ? Array.new : @selected_tags
case @do_what case @do_what
when '0' then when '0' then
@selected_tags.delete @tag.name #数组中删除有多方式 可以改用shift,pop @selected_tags.delete @tag #数组中删除有多方式 可以改用shift,pop
@selected_tag_ids.delete @tag.id.to_s
@selected_tag_objs.delete @tag
when '1' then when '1' then
# 判断是否已存在该tag 主要用来处理分页的情况 # 判断是否已存在该tag 主要用来处理分页的情况
unless @selected_tags.include? @tag.name unless @selected_tags.include? @tag
@selected_tags << @tag.name @selected_tags << @tag
@selected_tag_ids << @tag.id.to_s
@selected_tag_objs << @tag
end end
end end
end end
@ -92,7 +75,7 @@ class TagsController < ApplicationController
@attachments_results, @attachments_results,
@contests_results, @contests_results,
@courses_results, @courses_results,
@open_source_projects_results= refresh_results(@obj_id,@obj_flag,@selected_tags,@selected_tag_ids) @open_source_projects_results= refresh_results(@obj_id,@obj_flag,@selected_tags)
# 这里是做tag推荐用的 用来生产推荐的tags # 这里是做tag推荐用的 用来生产推荐的tags
unless @obj.nil? unless @obj.nil?
@ -102,13 +85,6 @@ class TagsController < ApplicationController
# @tags.delete(i) # @tags.delete(i)
# end # end
@related_tags = @tags @related_tags = @tags
@tag_objs = @obj.tags
@tag_objs.each do |t|
unless @selected_tags.include?(t.name)
@related_tag_ids << t.id.to_s
@related_tag_objs << t
end
end
else else
return return
end end
@ -186,8 +162,8 @@ class TagsController < ApplicationController
if request.get? if request.get?
# 获取传过来的tag_id taggable_id 和 taggable_type,通过2者确定要删除tag的对象 # 获取传过来的tag_id taggable_id 和 taggable_type,通过2者确定要删除tag的对象
@tag_id = params[:tag_name] @tag_name = params[:tag_name]
@tag_name = (ActsAsTaggableOn::Tag.find(@tag_id)).name @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id
@taggable_id = params[:taggable_id] # 当做参数传时对象会变成字符串 @taggable_id = params[:taggable_id] # 当做参数传时对象会变成字符串
@taggable_type = numbers_to_object_type(params[:taggable_type]) @taggable_type = numbers_to_object_type(params[:taggable_type])
@ -216,7 +192,7 @@ class TagsController < ApplicationController
private private
# 这里用来刷新搜索结果的区域 # 这里用来刷新搜索结果的区域
# 函数的返回值 前2字段用来处理获取其他tag和分页 另外4个返回值为过滤结果 # 函数的返回值 前2字段用来处理获取其他tag和分页 另外4个返回值为过滤结果
def refresh_results(obj_id,obj_flag,selected_tags,selected_tag_ids = nil) def refresh_results(obj_id,obj_flag,selected_tags)
@users_results = nil @users_results = nil
@projects_results = nil @projects_results = nil
@issues_results = nil @issues_results = nil
@ -234,36 +210,36 @@ class TagsController < ApplicationController
case obj_flag case obj_flag
when '1' then when '1' then
@obj = User.find_by_id(obj_id) @obj = User.find_by_id(obj_id)
@obj_pages,@users_results,@results_count = for_pagination(get_users_by_tag(selected_tags,selected_tag_ids)) @obj_pages,@users_results,@results_count = for_pagination(get_users_by_tag(selected_tags))
when '2' then when '2' then
@obj = Project.find_by_id(obj_id) @obj = Project.find_by_id(obj_id)
@obj_pages,@projects_results,@results_count = for_pagination(get_projects_by_tag(selected_tags,selected_tag_ids)) @obj_pages,@projects_results,@results_count = for_pagination(get_projects_by_tag(selected_tags))
when '3' then when '3' then
@obj = Issue.find_by_id(obj_id) @obj = Issue.find_by_id(obj_id)
@obj_pages,@issues_results,@results_count = for_pagination(get_issues_by_tag(selected_tags,selected_tag_ids)) @obj_pages,@issues_results,@results_count = for_pagination(get_issues_by_tag(selected_tags))
when '4' then when '4' then
@obj_pages,@bids_results,@results_count = for_pagination(get_bids_by_tag(selected_tags,selected_tag_ids)) @obj_pages,@bids_results,@results_count = for_pagination(get_bids_by_tag(selected_tags))
@obj = Bid.find_by_id(obj_id) @obj = Bid.find_by_id(obj_id)
when '5' when '5'
@obj = Forum.find_by_id(obj_id) @obj = Forum.find_by_id(obj_id)
@obj_pages,@forums_results,@results_count = for_pagination(get_forums_by_tag(selected_tags,selected_tag_ids)) @obj_pages,@forums_results,@results_count = for_pagination(get_forums_by_tag(selected_tags))
when '6' when '6'
@obj = Attachment.find_by_id(obj_id) @obj = Attachment.find_by_id(obj_id)
# modifed by Long Jun # modifed by Long Jun
# this is used to find the attachments that came from the same project and tagged with the same tag. # this is used to find the attachments that came from the same project and tagged with the same tag.
#@result = get_attachments_by_project_tag(selected_tags, @obj) #@result = get_attachments_by_project_tag(selected_tags, @obj)
@result = get_attachments_by_tag(selected_tags,selected_tag_ids) @result = get_attachments_by_tag(selected_tags)
@obj_pages, @attachments_results, @results_count = for_pagination(@result) @obj_pages, @attachments_results, @results_count = for_pagination(@result)
when '7' when '7'
@obj = Contest.find_by_id(obj_id) @obj = Contest.find_by_id(obj_id)
@obj_pages,@contests_results,@results_count = for_pagination(get_contests_by_tag(selected_tags,selected_tag_ids)) @obj_pages,@contests_results,@results_count = for_pagination(get_contests_by_tag(selected_tags))
when '8' when '8'
@obj = OpenSourceProject.find_by_id(obj_id) @obj = OpenSourceProject.find_by_id(obj_id)
@obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags,selected_tag_ids)) @obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags))
when '9' then when '9' then
@obj = Course.find_by_id(obj_id) @obj = Course.find_by_id(obj_id)
@obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags,selected_tag_ids)) @obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags))
else else
@obj = nil @obj = nil
end end

@ -75,8 +75,8 @@ module AttachmentsHelper
# this method is used to get all projects that tagged one tag # this method is used to get all projects that tagged one tag
# added by william # added by william
def get_attachments_by_tag(tag_name,selected_tag_ids = nil) def get_attachments_by_tag(tag_name)
Attachment.tagged_with(tag_name,{},selected_tag_ids).order('created_on desc') Attachment.tagged_with(tag_name).order('created_on desc')
end end
# this method is used to get all attachments that from one project and tagged one tag # this method is used to get all attachments that from one project and tagged one tag

@ -35,8 +35,8 @@ module BidsHelper
# this method is used to get all projects that tagged one tag # this method is used to get all projects that tagged one tag
# added by william # added by william
def get_bids_by_tag(tag_name,selected_tag_ids = nil) def get_bids_by_tag(tag_name)
Bid.tagged_with(tag_name,{},selected_tag_ids).order('updated_on desc') Bid.tagged_with(tag_name).order('updated_on desc')
end end
#added by huang #added by huang

@ -35,8 +35,8 @@ module ContestsHelper
# this method is used to get all projects that tagged one tag # this method is used to get all projects that tagged one tag
# added by william # added by william
def get_contests_by_tag(tag_name,selected_tag_ids = nil) def get_contests_by_tag(tag_name)
Contest.tagged_with(tag_name,{},selected_tag_ids).order('updated_on desc') Contest.tagged_with(tag_name).order('updated_on desc')
end end
#added by huang #added by huang

@ -449,8 +449,8 @@ module CoursesHelper
return homework_users return homework_users
end end
def get_courses_by_tag(tag_name,selected_tag_ids = nil) def get_courses_by_tag(tag_name)
Course.tagged_with(tag_name,{},selected_tag_ids).order('updated_at desc') Course.tagged_with(tag_name).order('updated_at desc')
end end
#课程实践年份下拉框 #课程实践年份下拉框

@ -22,7 +22,7 @@ module ForumsHelper
# this method is used to get all projects that tagged one tag # this method is used to get all projects that tagged one tag
# added by william # added by william
def get_forums_by_tag(tag_name,selected_tag_ids = nil) def get_forums_by_tag(tag_name)
Forum.tagged_with(tag_name,{},selected_tag_ids).order('updated_at desc') Forum.tagged_with(tag_name).order('updated_at desc')
end end
end end

@ -382,8 +382,8 @@ module IssuesHelper
# this method is used to get all projects that tagged one tag # this method is used to get all projects that tagged one tag
# added by william # added by william
def get_issues_by_tag(tag_name,selected_tag_ids = nil) def get_issues_by_tag(tag_name)
Issue.tagged_with(tag_name,{},selected_tag_ids).order('updated_on desc') Issue.tagged_with(tag_name).order('updated_on desc')
end end
end end

@ -31,8 +31,8 @@ module OpenSourceProjectsHelper
s = content_tag('div', s, :class => 'user_tags') s = content_tag('div', s, :class => 'user_tags')
end end
def get_open_source_projects_by_tag(tag_name,selected_tag_ids = nil) def get_open_source_projects_by_tag(tag_name)
OpenSourceProject.tagged_with(tag_name,{},selected_tag_ids).order('created_at desc') OpenSourceProject.tagged_with(tag_name).order('created_at desc')
end end
def show_origin(url) def show_origin(url)

@ -232,8 +232,8 @@ module ProjectsHelper
# this method is used to get all projects that tagged one tag # this method is used to get all projects that tagged one tag
# added by william # added by william
def get_projects_by_tag(tag_name,selected_tag_ids = nil) def get_projects_by_tag(tag_name)
Project.tagged_with(tag_name,{},selected_tag_ids).order('updated_on desc') Project.tagged_with(tag_name).order('updated_on desc')
end end
# added by fq # added by fq

@ -57,8 +57,8 @@ module UsersHelper
# this method is used to get all projects that tagged one tag # this method is used to get all projects that tagged one tag
# added by william # added by william
def get_users_by_tag(tag_name,selected_tag_ids = nil) def get_users_by_tag(tag_name)
User.tagged_with(tag_name,{},selected_tag_ids).order('updated_on desc') User.tagged_with(tag_name).order('updated_on desc')
end end
# added by fq # added by fq

@ -62,7 +62,7 @@
描&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;述&nbsp;&nbsp; 描&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;述&nbsp;&nbsp;
</strong> </strong>
<span style="margin-left:-10px;padding-right: 20px;"> <span style="margin-left:-10px;padding-right: 20px;">
<%= f.text_area "description", :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;", :maxlength => 65534 %> <%= f.text_area "description", :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;", :maxlength => 5000 %>
</span> </span>
</p> </p>
<p style="padding-left: 60px"> <p style="padding-left: 60px">

@ -5,14 +5,14 @@
<% i += 1 %> <% i += 1 %>
<li> <li>
<%= link_to image_tag("/images/sidebar/add.png"),:action => "index", <%= link_to image_tag("/images/sidebar/add.png"),:action => "index",
:current_selected_tags => selected_tags,:tag => rt.id,:do_what => "1", :current_selected_tags => selected_tags,:tag => rt,:do_what => "1",
:obj_id => obj_id,:object_flag => obj_flag %> :obj_id => obj_id,:object_flag => obj_flag %>
<span id="tag"> <span id="tag">
<%= rt.name %> <%= rt %>
</span> </span>
<% break if i >= 10 %> <% break if i >= 10 %>
<!-- 这里用例计数某类对象的所有该tag总数 --> <!-- 这里用例计数某类对象的所有该tag总数 -->
<%= render :partial => 'sidebar_tags',:locals => {:show_flag => obj_flag,:sg => rt,:selected_tag_ids => related_tag_ids }%> <%= render :partial => 'sidebar_tags',:locals => {:show_flag => obj_flag,:sg => rt }%>
</li> </li>
<% end %> <% end %>
</ul> </ul>

@ -3,10 +3,10 @@
<% for sg in selected_tags %> <% for sg in selected_tags %>
<li> <li>
<%= link_to image_tag("/images/sidebar/minus.png"),:action => "index", <%= link_to image_tag("/images/sidebar/minus.png"),:action => "index",
:current_selected_tags => selected_tags ,:tag => sg.id,:do_what => "0", :current_selected_tags => selected_tags ,:tag => sg,:do_what => "0",
:obj_id => obj_id,:object_flag => obj_flag %> :obj_id => obj_id,:object_flag => obj_flag %>
<span id="tag"><%= sg.name %> </span> <span id="tag"><%= sg %> </span>
<%= render :partial => 'sidebar_tags',:locals => {:show_flag => obj_flag,:sg => sg ,:selected_tag_ids => @selected_tag_ids}%> <%= render :partial => 'sidebar_tags',:locals => {:show_flag => obj_flag,:sg => sg }%>
</li> </li>
<% end %> <% end %>
</ul> </ul>

@ -1,14 +1,14 @@
<% case show_flag%> <% case show_flag%>
<% when '1' then %> <% when '1' then %>
(<%= User.tagged_with("#{sg.name}",{},selected_tag_ids).size %>) (<%= User.tagged_with("#{sg}").size %>)
<%when '2' then %> <%when '2' then %>
(<%= Project.tagged_with(sg.name,{},selected_tag_ids).size %>) (<%= Project.tagged_with(sg).size %>)
<% when '3' then %> <% when '3' then %>
(<%= Issue.tagged_with("#{sg.name}",{},selected_tag_ids).size %>) (<%= Issue.tagged_with("#{sg}").size %>)
<% when '4' then %> <% when '4' then %>
(<%= Bid.tagged_with("#{sg.name}",{},selected_tag_ids).size %>) (<%= Bid.tagged_with("#{sg}").size %>)
<% when '5' then %> <% when '5' then %>
(<%= Forum.tagged_with("#{sg.name}",{},selected_tag_ids).size %>) (<%= Forum.tagged_with("#{sg}").size %>)
<% when '6' then %> <% when '6' then %>
(<%= Attachment.tagged_with("#{sg.name}",{},selected_tag_ids).size %>) (<%= Attachment.tagged_with("#{sg}").size %>)
<% end %> <% end %>

@ -8,7 +8,7 @@
// }) // })
</script> </script>
<!-- 1代表是user类型 2代表是project类型 3代表是issue类型 4代表需求 9代表课程--> <!-- 1代表是user类型 2代表是project类型 3代表是issue类型 4代表需求 9代表课程-->
<% @tags = obj.reload.tags %> <% @tags = obj.reload.tag_list %>
<% if non_list_all and (@tags.size > 0) %> <% if non_list_all and (@tags.size > 0) %>
<!-- 这里是显示的非主页的tag 所以当tag数量较多时 不必全部显示 用“更多”代替 --> <!-- 这里是显示的非主页的tag 所以当tag数量较多时 不必全部显示 用“更多”代替 -->

@ -3,13 +3,13 @@
<h3><strong><%= l(:label_tags_selected) %></strong></h3> <h3><strong><%= l(:label_tags_selected) %></strong></h3>
<div id="selected_tags"> <div id="selected_tags">
<%= render :partial => "selected_tags",:locals => { <%= render :partial => "selected_tags",:locals => {
:selected_tags => @selected_tag_objs,:obj_flag => @obj_flag,:obj_id => @obj_id }%> :selected_tags => @selected_tags,:obj_flag => @obj_flag,:obj_id => @obj_id }%>
</div> </div>
<h3><strong><%= l(:label_tags_related) %></strong></h3> <h3><strong><%= l(:label_tags_related) %></strong></h3>
<div id="related_tags"> <div id="related_tags">
<%= render :partial => "related_tags",:locals => {:related_tags => @related_tag_objs, <%= render :partial => "related_tags",:locals => {:related_tags => @related_tags,
:selected_tags => @selected_tag_ids,:related_tag_ids => @related_tag_ids,:obj_flag => @obj_flag,:obj_id => @obj_id }%> :selected_tags => @selected_tags,:obj_flag => @obj_flag,:obj_id => @obj_id }%>
</div> </div>
</div> </div>
<% end %> <% end %>

@ -108,19 +108,19 @@ module ActsAsTaggableOn::Taggable
if owned_by if owned_by
joins << "JOIN #{ActsAsTaggableOn::Tagging.table_name}" + joins << "JOIN #{ActsAsTaggableOn::Tagging.table_name}" +
" ON #{ActsAsTaggableOn::Tagging.table_name}.taggable_id = #{quote}#{table_name}#{quote}.#{primary_key}" + " ON #{ActsAsTaggableOn::Tagging.table_name}.taggable_id = #{quote}#{table_name}#{quote}.#{primary_key}" +
" AND #{ActsAsTaggableOn::Tagging.table_name}.taggable_type = #{quote_value(base_class.name)}" + " AND #{ActsAsTaggableOn::Tagging.table_name}.taggable_type = #{quote_value(base_class.name)}" +
" AND #{ActsAsTaggableOn::Tagging.table_name}.tagger_id = #{owned_by.id}" + " AND #{ActsAsTaggableOn::Tagging.table_name}.tagger_id = #{owned_by.id}" +
" AND #{ActsAsTaggableOn::Tagging.table_name}.tagger_type = #{quote_value(owned_by.class.base_class.to_s)}" " AND #{ActsAsTaggableOn::Tagging.table_name}.tagger_type = #{quote_value(owned_by.class.base_class.to_s)}"
end end
elsif options.delete(:any) elsif options.delete(:any)
# get tags, drop out if nothing returned (we need at least one) # get tags, drop out if nothing returned (we need at least one)
tags = if options.delete(:wild) tags = if options.delete(:wild)
ActsAsTaggableOn::Tag.named_like_any(tag_list) ActsAsTaggableOn::Tag.named_like_any(tag_list)
else else
ActsAsTaggableOn::Tag.named_any(tag_list) ActsAsTaggableOn::Tag.named_any(tag_list)
end end
return empty_result unless tags.length > 0 return empty_result unless tags.length > 0
@ -129,12 +129,12 @@ module ActsAsTaggableOn::Taggable
taggings_context = context ? "_#{context}" : '' taggings_context = context ? "_#{context}" : ''
taggings_alias = adjust_taggings_alias( taggings_alias = adjust_taggings_alias(
"#{alias_base_name[0..4]}#{taggings_context[0..6]}_taggings_#{sha_prefix(tags.map(&:name).join('_'))}" "#{alias_base_name[0..4]}#{taggings_context[0..6]}_taggings_#{sha_prefix(tags.map(&:name).join('_'))}"
) )
tagging_join = "JOIN #{ActsAsTaggableOn::Tagging.table_name} #{taggings_alias}" + tagging_join = "JOIN #{ActsAsTaggableOn::Tagging.table_name} #{taggings_alias}" +
" ON #{taggings_alias}.taggable_id = #{quote}#{table_name}#{quote}.#{primary_key}" + " ON #{taggings_alias}.taggable_id = #{quote}#{table_name}#{quote}.#{primary_key}" +
" AND #{taggings_alias}.taggable_type = #{quote_value(base_class.name)}" " AND #{taggings_alias}.taggable_type = #{quote_value(base_class.name)}"
tagging_join << " AND " + sanitize_sql(["#{taggings_alias}.context = ?", context.to_s]) if context tagging_join << " AND " + sanitize_sql(["#{taggings_alias}.context = ?", context.to_s]) if context
# don't need to sanitize sql, map all ids and join with OR logic # don't need to sanitize sql, map all ids and join with OR logic
@ -142,12 +142,12 @@ module ActsAsTaggableOn::Taggable
select_clause = "DISTINCT #{table_name}.*" unless context and tag_types.one? select_clause = "DISTINCT #{table_name}.*" unless context and tag_types.one?
if owned_by if owned_by
tagging_join << " AND " + tagging_join << " AND " +
sanitize_sql([ sanitize_sql([
"#{taggings_alias}.tagger_id = ? AND #{taggings_alias}.tagger_type = ?", "#{taggings_alias}.tagger_id = ? AND #{taggings_alias}.tagger_type = ?",
owned_by.id, owned_by.id,
owned_by.class.base_class.to_s owned_by.class.base_class.to_s
]) ])
end end
joins << tagging_join joins << tagging_join
@ -159,19 +159,19 @@ module ActsAsTaggableOn::Taggable
tags.each do |tag| tags.each do |tag|
taggings_alias = adjust_taggings_alias("#{alias_base_name[0..11]}_taggings_#{sha_prefix(tag.name)}") taggings_alias = adjust_taggings_alias("#{alias_base_name[0..11]}_taggings_#{sha_prefix(tag.name)}")
tagging_join = "JOIN #{ActsAsTaggableOn::Tagging.table_name} #{taggings_alias}" + tagging_join = "JOIN #{ActsAsTaggableOn::Tagging.table_name} #{taggings_alias}" +
" ON #{taggings_alias}.taggable_id = #{quote}#{table_name}#{quote}.#{primary_key}" + " ON #{taggings_alias}.taggable_id = #{quote}#{table_name}#{quote}.#{primary_key}" +
" AND #{taggings_alias}.taggable_type = #{quote_value(base_class.name)}" + " AND #{taggings_alias}.taggable_type = #{quote_value(base_class.name)}" +
" AND #{taggings_alias}.tag_id = #{tag.id}" " AND #{taggings_alias}.tag_id = #{tag.id}"
tagging_join << " AND " + sanitize_sql(["#{taggings_alias}.context = ?", context.to_s]) if context tagging_join << " AND " + sanitize_sql(["#{taggings_alias}.context = ?", context.to_s]) if context
if owned_by if owned_by
tagging_join << " AND " + tagging_join << " AND " +
sanitize_sql([ sanitize_sql([
"#{taggings_alias}.tagger_id = ? AND #{taggings_alias}.tagger_type = ?", "#{taggings_alias}.tagger_id = ? AND #{taggings_alias}.tagger_type = ?",
owned_by.id, owned_by.id,
owned_by.class.base_class.to_s owned_by.class.base_class.to_s
]) ])
end end
joins << tagging_join joins << tagging_join
@ -182,8 +182,8 @@ module ActsAsTaggableOn::Taggable
if options.delete(:match_all) if options.delete(:match_all)
joins << "LEFT OUTER JOIN #{ActsAsTaggableOn::Tagging.table_name} #{taggings_alias}" + joins << "LEFT OUTER JOIN #{ActsAsTaggableOn::Tagging.table_name} #{taggings_alias}" +
" ON #{taggings_alias}.taggable_id = #{quote}#{table_name}#{quote}.#{primary_key}" + " ON #{taggings_alias}.taggable_id = #{quote}#{table_name}#{quote}.#{primary_key}" +
" AND #{taggings_alias}.taggable_type = #{quote_value(base_class.name)}" " AND #{taggings_alias}.taggable_type = #{quote_value(base_class.name)}"
group_columns = ActsAsTaggableOn::Tag.using_postgresql? ? grouped_column_names_for(self) : "#{table_name}.#{primary_key}" group_columns = ActsAsTaggableOn::Tag.using_postgresql? ? grouped_column_names_for(self) : "#{table_name}.#{primary_key}"
@ -355,7 +355,7 @@ module ActsAsTaggableOn::Taggable
new_tags |= current_tags[index...current_tags.size] & shared_tags new_tags |= current_tags[index...current_tags.size] & shared_tags
# Order the array of tag objects to match the tag list # Order the array of tag objects to match the tag list
new_tags = tags.map do |t| new_tags = tags.map do |t|
new_tags.find { |n| n.name.downcase == t.name.downcase } new_tags.find { |n| n.name.downcase == t.name.downcase }
end.compact end.compact
end end

Loading…
Cancel
Save