Created
August 7, 2010 20:03
-
-
Save Veejay/513130 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PhotosController < ApplicationController | |
layout "photos" | |
def moderate | |
start = PhotoCursor.instance.profile_photos_cursor | |
@primary = params[:other].blank? | |
@photos = RemotePhoto.get(:next, :start => start, :limit => PhotoCursor::SET_SIZE, :profile_photo => @primary) | |
if request.post? | |
RemotePhoto.put(:bulk_update, {:photos => params[:photos]}) | |
update_moderation_stats(params[:photos]) | |
render :partial => "photos" | |
end | |
end | |
def rejected | |
@photos = RemotePhoto.get(:rejected) | |
# We want to render a different partial here, complete with pagination | |
render :moderate | |
end | |
def approved | |
@photos = RemotePhoto.get(:approved) | |
# We want to render a different partial here, complete with pagination | |
render :moderate | |
end | |
private | |
# Hate me all you can, but ActiveRecord can simply not handle that kind of scenario without raping performance | |
def update_moderation_stats(photos) | |
query = "INSERT INTO moderation_statistics (photo_id, moderator_id, approved, created_at, updated_at) VALUES " | |
values = [] | |
photos.each do |k,v| | |
values << "(#{k}, 1, #{v}, NOW(), NOW())" | |
end | |
ActiveRecord::Base.connection.execute(query << values.join(",")) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment