photomix/app/controllers/albums_controller.rb

116 lines
4.3 KiB
Ruby
Raw Normal View History

2009-05-22 14:13:46 +02:00
class AlbumsController < ApplicationController
2009-08-03 16:39:33 +02:00
before_filter :check_public_access
2012-07-24 23:26:16 +02:00
skip_before_filter :authenticate_user!, :only => [:index, :show]
2009-05-22 14:13:46 +02:00
def index
2012-07-30 21:08:48 +02:00
add_breadcrumb t('activerecord.models.album.popular'), collections_path, :title => t('activerecord.models.album.popular')
add_breadcrumb t('activerecord.actions.create', :model => I18n.t('activerecord.models.album.single')), new_album_path,
:title => t('activerecord.actions.create', :model => I18n.t('activerecord.models.album.single')),
:li_icon => 'icon-plus-sign'
if params[:tag_id]
2012-07-24 23:26:16 +02:00
@albums = Album.where(:conditions => [ "id IN ( SELECT DISTINCT photos.album_id FROM photos WHERE photos.id IN ( SELECT photo_id FROM photo_tags WHERE photo_tags.tag_id = :q) )", { :q => Tag.find( params[:tag_id] ).id } ]).order('title')
elsif params[:q]
#search = params[:q]
#search = search.split("AND").map{|q|q.strip}
#@albums = Album.find(:all, :select => 'DISTINCT albums.id, albums.title', :limit => 20, :conditions => { :tags => {:title => search}}, :joins => 'LEFT OUTER JOIN photos ON albums.id = photos.album_id LEFT OUTER JOIN photo_tags ON photos.id = photo_tags.photo_id LEFT OUTER JOIN tags ON photo_tags.tag_id = tags.id', :order => "albums.title ASC" )
2009-08-12 15:42:18 +02:00
#@albums = Album.find(:all, :select => 'DISTINCT album_id', :conditions => [ "title LIKE :q OR description LIKE :q OR id IN ( SELECT DISTINCT photos.album_id FROM photos WHERE photos.description LIKE :q OR photos.title LIKE :q OR photos.id IN ( SELECT photo_id FROM photo_tags LEFT OUTER JOIN tags ON photo_tags.tag_id = tags.id WHERE tags.title LIKE :q) )", { :q => '%' + params[:q] + '%' } ], :order => 'title')
params[:q].split(" AND ").each {|q|
qphotos = Photo.find(:all, :select => 'DISTINCT album_id', :conditions => [ "description LIKE :q OR title LIKE :q OR id IN ( SELECT photo_id FROM photo_tags LEFT OUTER JOIN tags ON photo_tags.tag_id = tags.id WHERE tags.title LIKE :q)", { :q => '%' + q + '%' } ])
qalbums = Album.find(:all, :conditions => ['title LIKE :q OR description LIKE :q OR id IN (:ids)', { :ids => qphotos.map{|p|p.album_id}, :q => '%' + q + '%' }], :order => 'title' )
if @albums
@albums = @albums & qalbums
else
@albums = qalbums
end
}
else
2012-07-29 00:33:03 +02:00
@albums = Album.popular.page(@page).per(@per_page)
end
2009-05-22 14:13:46 +02:00
respond_to do |format|
format.html
format.json { render :json => @albums }
format.xml { render :xml => @albums }
end
end
2009-06-03 01:33:39 +02:00
def untouched
@albums = Album.untouched()
respond_to do |format|
format.html
format.json { render :json => @albums }
format.xml { render :xml => @albums }
end
end
2009-05-22 14:13:46 +02:00
def show
2009-06-16 01:18:42 +02:00
@album = Album.find( params[:id])
2012-07-29 00:33:03 +02:00
@photos = @album.photos.popular
2009-05-22 14:13:46 +02:00
respond_to do |format|
format.html
format.json { render :json => @album }
format.xml { render :xml => @album }
2009-05-25 21:39:43 +02:00
format.pdf { render :pdf => @album.title }
2009-05-22 14:13:46 +02:00
end
end
2009-05-22 21:04:41 +02:00
def new
@album = Album.new
end
def create
@album = Album.new(params[:album])
2009-08-12 15:42:18 +02:00
2009-05-22 21:04:41 +02:00
if @album.save
flash[:notice] = "Album created! Now add some nice photos."
if params[:collection_id]
2009-06-30 22:41:27 +02:00
@album.collections << Collection.find( params[:collection_id] )
redirect_to upload_collection_album_photos_path(params[:collection_id], @album )
else
redirect_to upload_album_photos_path( @album )
2009-06-30 22:41:27 +02:00
end
2009-05-22 21:04:41 +02:00
else
render :action => :new
end
end
2009-05-22 21:04:41 +02:00
def edit
@album = Album.find( params[:id])
end
def update
@album = Album.find( params[:id])
if @album.update_attributes(params[:album])
2009-06-09 00:30:22 +02:00
flash[:notice] = "Album updated!"
if params[:collection_id]
redirect_to collection_album_path(params[:collection_id], @album )
else
redirect_to @album
end
2009-05-22 21:04:41 +02:00
else
render :action => :edit
end
end
2009-06-02 00:08:57 +02:00
def destroy
2009-05-22 21:04:41 +02:00
@album = Album.find( params[:id])
2009-06-02 00:08:57 +02:00
if @album.destroy
if params[:collection_id]
redirect_to collection_path(params[:collection_id] )
else
redirect_to albums_path
end
2009-05-22 21:04:41 +02:00
else
redirect_to @album
end
end
2012-07-29 00:33:03 +02:00
def rate
@album = Album.find(params[:id])
@album.rate(params[:stars], current_user, params[:dimension])
render :json => {:id => @album.wrapper_dom_id(params), :width => 125}
end
2009-05-22 14:13:46 +02:00
end