Sha256: c9a03630f42f626e9ad14b3612e30e27f015b648b8e8db5da802494524f85971

Contents?: true

Size: 1.97 KB

Versions: 2

Compression:

Stored size: 1.97 KB

Contents

class Admin::FeedbackController < Admin::BaseController
  def index
    conditions = ["(contents.type = 'Comment' or contents.type = 'Trackback')"]

    if params[:search]
      search_sql = "%#{params[:search]}%"
      conditions.first << ' and (url like ? or author like ? or title like ? or ip like ? or email like ?)'
      5.times { conditions.push search_sql }
    end

    if params[:published] == 'f'
      conditions.first << ' and (published = ?)'
      conditions.push false
    end

    @pages, @feedback = paginate(:contents, 
      :order => 'contents.created_at desc', 
      :conditions => conditions,
      :per_page => 40)
    
    render_action 'list'
  end
  
  def delete
    if request.post?
      feedback = Content.find(params[:id])
      if feedback.kind_of? Comment or feedback.kind_of? Trackback
        feedback.destroy
        flash[:notice] = "Deleted"
      else
        flash[:notice] = "Not found"
      end
    end
    redirect_to :action => 'index', :page => params[:page], :search => params[:search]
  end
  
  def bulkops
    STDERR.puts "Bulkops: #{params.inspect}"
    
    ids = (params[:feedback_check]||{}).keys.map(&:to_i)
    
    case params[:commit]
    when 'Delete Checked Items'
      count = 0
      ids.each do |id|
        count += Content.delete(id)
      end
      flash[:notice] = "Deleted #{count} item(s)"
    when 'Publish Checked Items'
      ids.each do |id|
        feedback = Content.find(id)
        feedback.attributes[:published] = true
        feedback.set_spam(false)
        feedback.save
      end
      flash[:notice]= "Published #{ids.size} item(s)"
    when 'Unpublish Checked Items'
      ids.each do |id|
        feedback = Content.find(id)
        feedback.withdraw!
        feedback.set_spam(true)
        feedback.save
      end
      flash[:notice]= "Unpublished #{ids.size} item(s)"
    else
      flash[:notice] = "Not implemented"
    end

    redirect_to :action => 'index', :page => params[:page], :search => params[:search]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
typo-3.99.4 app/controllers/admin/feedback_controller.rb
typo-4.0.0 app/controllers/admin/feedback_controller.rb