1 class DiaryEntryController < ApplicationController
2 layout 'site', :except => :rss
4 before_filter :set_locale
5 before_filter :authorize_web
6 before_filter :require_user, :only => [:new, :edit]
7 before_filter :check_database_readable
8 before_filter :check_database_writable, :only => [:new, :edit]
11 @title = 'New diary entry'
13 if params[:diary_entry]
14 @diary_entry = DiaryEntry.new(params[:diary_entry])
15 @diary_entry.user = @user
18 redirect_to :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name
20 render :action => 'edit'
23 render :action => 'edit'
28 @title= 'Edit diary entry'
29 @diary_entry = DiaryEntry.find(params[:id])
31 if @user != @diary_entry.user
32 redirect_to :controller => 'diary_entry', :action => 'view', :id => params[:id]
33 elsif params[:diary_entry]
34 if @diary_entry.update_attributes(params[:diary_entry])
35 redirect_to :controller => 'diary_entry', :action => 'view', :id => params[:id]
38 rescue ActiveRecord::RecordNotFound
39 render :action => "no_such_entry", :status => :not_found
43 @entry = DiaryEntry.find(params[:id])
44 @diary_comment = @entry.diary_comments.build(params[:diary_comment])
45 @diary_comment.user = @user
46 if @diary_comment.save
47 Notifier::deliver_diary_comment_notification(@diary_comment)
48 redirect_to :controller => 'diary_entry', :action => 'view', :display_name => @entry.user.display_name, :id => @entry.id
50 render :action => 'view'
55 if params[:display_name]
56 @this_user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
59 @title = @this_user.display_name + "'s diary"
60 @entry_pages, @entries = paginate(:diary_entries,
61 :conditions => ['user_id = ?', @this_user.id],
62 :order => 'created_at DESC',
65 @not_found_user = params[:display_name]
67 render :action => 'no_such_user', :status => :not_found
70 @title = "Users' diaries"
71 @entry_pages, @entries = paginate(:diary_entries, :include => :user,
72 :conditions => ["users.visible = ?", true],
73 :order => 'created_at DESC',
79 if params[:display_name]
80 user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
83 @entries = DiaryEntry.find(:all, :conditions => ['user_id = ?', user.id], :order => 'created_at DESC', :limit => 20)
84 @title = "OpenStreetMap diary entries for #{user.display_name}"
85 @description = "Recent OpenStreetmap diary entries from #{user.display_name}"
86 @link = "http://#{SERVER_URL}/user/#{user.display_name}/diary"
88 render :content_type => Mime::RSS
90 render :nothing => true, :status => :not_found
92 elsif params[:language]
93 @entries = DiaryEntry.find(:all, :include => :user,
94 :conditions => ["users.visible = ? AND diary_entries.language = ?", true, params[:language]],
95 :order => 'created_at DESC', :limit => 20)
96 @title = "OpenStreetMap diary entries in #{params[:language]}"
97 @description = "Recent diary entries from users of OpenStreetMap"
98 @link = "http://#{SERVER_URL}/diary/#{params[:language]}"
100 render :content_type => Mime::RSS
102 @entries = DiaryEntry.find(:all, :include => :user,
103 :conditions => ["users.visible = ?", true],
104 :order => 'created_at DESC', :limit => 20)
105 @title = "OpenStreetMap diary entries"
106 @description = "Recent diary entries from users of OpenStreetMap"
107 @link = "http://#{SERVER_URL}/diary"
109 render :content_type => Mime::RSS
114 user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
117 @entry = DiaryEntry.find(:first, :conditions => ['user_id = ? AND id = ?', user.id, params[:id]])
119 @title = "Users' diaries | #{params[:display_name]}"
121 render :action => 'no_such_entry', :status => :not_found
124 @not_found_user = params[:display_name]
126 render :action => 'no_such_user', :status => :not_found