Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drupal_tag => tag #1178

Merged
merged 1 commit into from Jan 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ def set_sidebar(type = :generic, data = :all, args = {})
args[:note_count] ||= 8
if type == :tags # accepts data of array of tag names as strings
if params[:controller] == 'questions'
@notes = @notes || DrupalTag.find_nodes_by_type(data, 'note', args[:note_count])
@notes = @notes || Tag.find_nodes_by_type(data, 'note', args[:note_count])
else
@notes = @notes || DrupalTag.find_research_notes(data, args[:note_count])
@notes = @notes || Tag.find_research_notes(data, args[:note_count])
end

@notes = @notes.where('node.nid != (?)', @node.nid) if @node
@wikis = DrupalTag.find_pages(data,10)
@videos = DrupalTag.find_nodes_by_type_with_all_tags(['video']+data,'note',8) if args[:videos] && data.length > 1
@maps = DrupalTag.find_nodes_by_type(data,'map',20)
@wikis = Tag.find_pages(data,10)
@videos = Tag.find_nodes_by_type_with_all_tags(['video']+data,'note',8) if args[:videos] && data.length > 1
@maps = Tag.find_nodes_by_type(data,'map',20)
else # type is generic
# remove "classroom" postings; also switch to an EXCEPT operator in sql, see https://github.com/publiclab/plots2/issues/375
hidden_nids = DrupalNode.joins(:drupal_node_community_tag)
Expand Down Expand Up @@ -192,7 +192,7 @@ def sort_question_by_tags
@session_tags = session[:tags]
qids = @questions.collect(&:nid)
@questions = DrupalNode.where(status: 1, type: 'note')
.joins(:drupal_tag)
.joins(:tag)
.where('term_data.name IN (?)', @session_tags.values)
.where('node.nid IN (?)', qids)
.group('node.nid')
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def dashboard
@wiki_count = DrupalNodeRevision.select(:timestamp)
.where(timestamp: Time.now.to_i - 1.weeks.to_i..Time.now.to_i)
.count
@blog = DrupalTag.find_nodes_by_type('blog', 'note', 1).first
@blog = Tag.find_nodes_by_type('blog', 'note', 1).first
# remove "classroom" postings; also switch to an EXCEPT operator in sql, see https://github.com/publiclab/plots2/issues/375
hidden_nids = DrupalNode.joins(:drupal_node_community_tag)
.joins("LEFT OUTER JOIN term_data ON term_data.tid = community_tags.tid")
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/map_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ def index
.order("nid DESC")
.where(type: 'map', status: 1)

# I'm not sure if this is actually eager loading the drupal_tags...
@maps = DrupalNode.joins(:drupal_tag)
# I'm not sure if this is actually eager loading the tags...
@maps = DrupalNode.joins(:tag)
.where('type = "map" AND status = 1 AND (term_data.name LIKE ? OR term_data.name LIKE ?)', 'lat:%', 'lon:%')
.uniq

# This is supposed to eager load the url_aliases, and seems to run, but doesn't actually eager load them...?
#@maps = DrupalNode.select("node.*,url_alias.dst AS dst").joins(:drupal_tag).where('type = "map" AND status = 1 AND (term_data.name LIKE ? OR term_data.name LIKE ?)', 'lat:%', 'lon:%').joins("INNER JOIN url_alias ON url_alias.src = CONCAT('node/',node.nid)")
#@maps = DrupalNode.select("node.*,url_alias.dst AS dst").joins(:tag).where('type = "map" AND status = 1 AND (term_data.name LIKE ? OR term_data.name LIKE ?)', 'lat:%', 'lon:%').joins("INNER JOIN url_alias ON url_alias.src = CONCAT('node/',node.nid)")
end

def show
Expand Down Expand Up @@ -206,7 +206,7 @@ def tag
set_sidebar :tags, [params[:id]], {:note_count => 20}

@tagnames = params[:id].split(',')
nids = DrupalTag.find_nodes_by_type(params[:id],'map',20).collect(&:nid)
nids = Tag.find_nodes_by_type(params[:id],'map',20).collect(&:nid)
@notes = DrupalNode.paginate(page: params[:page])
.where('nid in (?)', nids)
.order("nid DESC")
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def index
def methods
@title = "Methods"
@notes = DrupalNode.where(status: 1, type: ['page','tool'])
.includes(:drupal_node_revision, :drupal_tag)
.includes(:drupal_node_revision, :tag)
.where('term_data.name = ?','tool')
.page(params[:page])
.order("node_revisions.timestamp DESC")
Expand All @@ -29,7 +29,7 @@ def techniques
def places
@title = "Places"
@notes = DrupalNode.where(status: 1, type: ['page','place'])
.includes(:drupal_node_revision, :drupal_tag)
.includes(:drupal_node_revision, :tag)
.where('term_data.name = ?','chapter')
.page(params[:page])
.order("node_revisions.timestamp DESC")
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/questions_search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def index
'type = "note" AND node.status = 1 AND title LIKE ?',
"%" + params[:id] + "%"
)
.joins(:drupal_tag)
.joins(:tag)
.where('term_data.name LIKE ?', 'question:%')
.order('node.nid DESC')
.page(params[:page])
Expand All @@ -32,7 +32,7 @@ def typeahead
'type = "note" AND node.status = 1 AND title LIKE ?',
"%" + params[:id] + "%"
)
.joins(:drupal_tag)
.joins(:tag)
.where('term_data.name LIKE ?', 'question:%')
.order('node.nid DESC')
.limit(25)
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/subscription_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def add
if current_user
# assume tag, for now
if params[:type] == "tag"
tag = DrupalTag.find_by_name(params[:name])
tag = Tag.find_by_name(params[:name])
if tag.nil?
# if the tag doesn't exist, we should create it!
# this could fail validations; error out if so...
tag = DrupalTag.new({
tag = Tag.new({
:vid => 3, # vocabulary id
:name => params[:name],
:description => "",
Expand Down Expand Up @@ -86,7 +86,7 @@ def add
def delete
# assume tag, for now
if params[:type] == "tag"
id = DrupalTag.find_by_name(params[:name]).tid
id = Tag.find_by_name(params[:name]).tid
end
if id.nil?
flash[:error] = "You are not subscribed to '#{params[:name]}'"
Expand Down Expand Up @@ -114,7 +114,7 @@ def delete

def set_following(value,type,id)
# add swtich statement for different types: tag, node, user
if type == 'tag' && DrupalTag.find_by_tid(id)
if type == 'tag' && Tag.find_by_tid(id)
# Create the entry if it isn't already created.
# assume tag, for now:
subscription = TagSelection.where(:user_id => current_user.uid,
Expand All @@ -123,7 +123,7 @@ def set_following(value,type,id)

# Check if the value changed.
if subscription.following_changed?
#tag = DrupalTag.find(id)
#tag = Tag.find(id)
# we have to implement caching for tags if we want to adapt this code:
#if subscription.following
# node.cached_likes = node.cached_likes + 1
Expand Down
36 changes: 18 additions & 18 deletions app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TagController < ApplicationController
def index
@title = I18n.t('tag_controller.tags')
@paginated = true
@tags = DrupalTag.joins(:drupal_node_community_tag, :drupal_node)
@tags = Tag.joins(:drupal_node_community_tag, :drupal_node)
.where('node.status = ?', 1)
.paginate(:page => params[:page])
.order('count DESC')
Expand All @@ -27,16 +27,16 @@ def show
qids = DrupalNode.questions.where(status: 1).collect(&:nid)
if params[:id][-1..-1] == "*" # wildcard tags
@wildcard = true
@tags = DrupalTag.where('name LIKE (?)', params[:id][0..-2] + '%')
@tags = Tag.where('name LIKE (?)', params[:id][0..-2] + '%')
nodes = DrupalNode.where(status: 1, type: node_type)
.includes(:drupal_node_revision, :drupal_tag)
.includes(:drupal_node_revision, :tag)
.where('term_data.name LIKE (?) OR term_data.parent LIKE (?)', params[:id][0..-2] + '%', params[:id][0..-2] + '%')
.page(params[:page])
.order("node_revisions.timestamp DESC")
else
@tags = DrupalTag.find_all_by_name params[:id]
@tags = Tag.find_all_by_name params[:id]
nodes = DrupalNode.where(status: 1, type: node_type)
.includes(:drupal_node_revision, :drupal_tag)
.includes(:drupal_node_revision, :tag)
.where('term_data.name = ? OR term_data.parent = ?', params[:id], params[:id])
.page(params[:page])
.order("node_revisions.timestamp DESC")
Expand Down Expand Up @@ -67,19 +67,19 @@ def show

def widget
num = params[:n] || 4
nids = DrupalTag.find_nodes_by_type(params[:id],'note',num).collect(&:nid)
nids = Tag.find_nodes_by_type(params[:id],'note',num).collect(&:nid)
@notes = DrupalNode.page(params[:page])
.where('status = 1 AND nid in (?)', nids)
.order("nid DESC")
render :layout => false
end

def blog
nids = DrupalTag.find_nodes_by_type(params[:id],'note',20).collect(&:nid)
nids = Tag.find_nodes_by_type(params[:id],'note',20).collect(&:nid)
@notes = DrupalNode.paginate(:page => params[:page], :per_page => 6)
.where('status = 1 AND nid in (?)', nids)
.order("nid DESC")
@tags = DrupalTag.find_all_by_name params[:id]
@tags = Tag.find_all_by_name params[:id]
@tagnames = @tags.collect(&:name).uniq! || []
@title = @tagnames.join(',') + " Blog" if @tagnames
end
Expand All @@ -91,7 +91,7 @@ def author
def barnstar
node = DrupalNode.find params[:nid]
tagname = "barnstar:"+params[:star]
if DrupalTag.exists?(tagname,params[:nid])
if Tag.exists?(tagname,params[:nid])
flash[:error] = I18n.t('tag_controller.tag_already_exists')
elsif !node.add_barnstar(tagname.strip,current_user)
flash[:error] = I18n.t('tag_controller.barnstar_not_created')
Expand Down Expand Up @@ -122,7 +122,7 @@ def create

# this should all be done in the model:

if DrupalTag.exists?(tagname, params[:nid])
if Tag.exists?(tagname, params[:nid])
@output[:errors] << I18n.t('tag_controller.tag_already_exists')
elsif node.can_tag(tagname, current_user) === true || current_user.role == "admin"# || current_user.role == "moderator"
saved, tag = node.add_tag(tagname.strip, current_user)
Expand Down Expand Up @@ -178,7 +178,7 @@ def suggested
if params[:id].length > 2
@suggestions = []
# filtering out tag spam by requiring tags attached to a published node
DrupalTag.where('name LIKE ?', "%" + params[:id] + "%")
Tag.where('name LIKE ?', "%" + params[:id] + "%")
.includes(:drupal_node)
.where('node.status = 1')
.limit(10).each do |tag|
Expand All @@ -193,12 +193,12 @@ def suggested
def rss
if params[:tagname][-1..-1] == "*"
@notes = DrupalNode.where(:status => 1, :type => 'note')
.includes(:drupal_node_revision,:drupal_tag)
.includes(:drupal_node_revision,:tag)
.where('term_data.name LIKE (?)', params[:tagname][0..-2]+'%')
.limit(20)
.order("node_revisions.timestamp DESC")
else
@notes = DrupalTag.find_nodes_by_type([params[:tagname]],'note',20)
@notes = Tag.find_nodes_by_type([params[:tagname]],'note',20)
end
respond_to do |format|
format.rss {
Expand All @@ -217,9 +217,9 @@ def rss
def contributors
set_sidebar :tags, [params[:id]], {:note_count => 20}
@tagnames = [params[:id]]
@tag = DrupalTag.find_by_name params[:id]
@tag = Tag.find_by_name params[:id]
@notes = DrupalNode.where(:status => 1, :type => 'note')
.includes(:drupal_node_revision,:drupal_tag)
.includes(:drupal_node_revision,:tag)
.where('term_data.name = ?', params[:id])
.order("node_revisions.timestamp DESC")
@users = @notes.collect(&:author).uniq
Expand All @@ -232,10 +232,10 @@ def contributors_index
@tags = []

@tagnames.each do |tagname|
tag = DrupalTag.find_by_name(tagname)
tag = Tag.find_by_name(tagname)
@tags << tag if tag
@tagdata[tagname] = {}
t = DrupalTag.find :all, :conditions => {:name => tagname}
t = Tag.find :all, :conditions => {:name => tagname}
nct = DrupalNodeCommunityTag.find :all, :conditions => ['tid in (?)',t.collect(&:tid)]
@tagdata[tagname][:users] = DrupalNode.find(:all, :conditions => ['nid IN (?)',(nct).collect(&:nid)]).collect(&:author).uniq.length
@tagdata[tagname][:wikis] = DrupalNode.count :all, :conditions => ["nid IN (?) AND (type = 'page' OR type = 'tool' OR type = 'place')", (nct).collect(&:nid)]
Expand All @@ -252,7 +252,7 @@ def add_tag
end
tagnames = params[:name].split(',')
tagnames.each do |tagname|
tag = DrupalTag.find_by_name(tagname)
tag = Tag.find_by_name(tagname)
if tag
session[:tags][tag.tid.to_s] = tagname
else
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def profile
def likes
@user = DrupalUsers.find_by_name(params[:id])
@title = "Liked by "+@user.name
@notes = @user.liked_notes.includes([:drupal_tag, :comments])
@notes = @user.liked_notes.includes([:tag, :comments])
.paginate(page: params[:page], per_page: 20)
@wikis = @user.liked_pages
@tagnames = []
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/wiki_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def show
return if check_and_redirect_node(@node)
if !@node.nil? # it's a place page!
@tags = @node.tags
@tags += [DrupalTag.find_by_name(params[:id])] if DrupalTag.find_by_name(params[:id])
@tags += [Tag.find_by_name(params[:id])] if Tag.find_by_name(params[:id])
else # it's a new wiki page!
@title = I18n.t('wiki_controller.new_wiki_page')
if current_user
Expand All @@ -61,7 +61,7 @@ def show
end
@tagnames = @tags.collect(&:name)
set_sidebar :tags, @tagnames, {:videos => true}
@wikis = DrupalTag.find_pages(@node.slug_from_path,30) if @node.has_tag('chapter') || @node.has_tag('tabbed:wikis')
@wikis = Tag.find_pages(@node.slug_from_path,30) if @node.has_tag('chapter') || @node.has_tag('tabbed:wikis')

impressionist(@node.drupal_node_counter)
@revision = @node.latest
Expand Down Expand Up @@ -111,9 +111,9 @@ def new
.order("node.nid DESC")
.where('type = "page" AND node.status = 1 AND (node.title LIKE ? OR node_revisions.body LIKE ?)', "%" + title + "%","%" + title + "%")
.includes(:drupal_node_revision)
tag = DrupalTag.find_by_name(params[:id]) # add page name as a tag, too
tag = Tag.find_by_name(params[:id]) # add page name as a tag, too
@tags << tag if tag
@related += DrupalTag.find_nodes_by_type(@tags.collect(&:name),'page',10)
@related += Tag.find_nodes_by_type(@tags.collect(&:name),'page',10)
end
render :template => 'wiki/edit'
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def insert_extras(body)
output += ' <th><a data-type="likes">Likes</a></th>'
output += ' </tr>'
nodes = DrupalNode.where(status: 1, type: 'note')
.includes(:drupal_node_revision, :drupal_tag)
.includes(:drupal_node_revision, :tag)
.where('term_data.name = ?', $1)
.page(params[:page])
.order("node_revisions.timestamp DESC")
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/subscription_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class SubscriptionMailer < ActionMailer::Base
def notify_node_creation(node)
subject = "[PublicLab] " + (node.has_power_tag('question') ? "Question: " : "") +
node.title
DrupalTag.subscribers(node.tags).each do |key,val|
Tag.subscribers(node.tags).each do |key,val|
@user = val[:user]
@node = node
@tags = val[:tags]
Expand Down
Loading