1 class DiaryEntryController < ApplicationController
2 layout 'site', :except => :rss
4 before_filter :authorize_web
5 before_filter :set_locale
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 = I18n.t('diary_entry.list.new')
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 @diary_entry = DiaryEntry.new(:language_code => @user.preferred_language)
24 render :action => 'edit'
29 @title= I18n.t('diary_entry.edit.title')
30 @diary_entry = DiaryEntry.find(params[:id])
32 if @user != @diary_entry.user
33 redirect_to :controller => 'diary_entry', :action => 'view', :id => params[:id]
34 elsif params[:diary_entry]
35 params[:diary_entry][:language] = Language.find_by_code(params[:diary_entry][:language])
36 params[:diary_entry][:language] = Language.find_by_code("en") if params[:diary_entry][:language].nil?
37 if @diary_entry.update_attributes(params[:diary_entry])
38 redirect_to :controller => 'diary_entry', :action => 'view', :id => params[:id]
41 rescue ActiveRecord::RecordNotFound
42 render :action => "no_such_entry", :status => :not_found
46 @entry = DiaryEntry.find(params[:id])
47 @diary_comment = @entry.diary_comments.build(params[:diary_comment])
48 @diary_comment.user = @user
49 if @diary_comment.save
50 Notifier::deliver_diary_comment_notification(@diary_comment)
51 redirect_to :controller => 'diary_entry', :action => 'view', :display_name => @entry.user.display_name, :id => @entry.id
53 render :action => 'view'
58 if params[:display_name]
59 @this_user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
62 @title = @this_user.display_name + "'s diary"
63 @entry_pages, @entries = paginate(:diary_entries,
64 :conditions => ['user_id = ?', @this_user.id],
65 :order => 'created_at DESC',
68 @not_found_user = params[:display_name]
70 render :action => 'no_such_user', :status => :not_found
73 @title = I18n.t('diary_entry.list.title')
74 @entry_pages, @entries = paginate(:diary_entries, :include => :user,
75 :conditions => ["users.visible = ?", true],
76 :order => 'created_at DESC',
82 if params[:display_name]
83 user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
86 @entries = DiaryEntry.find(:all, :conditions => ['user_id = ?', user.id], :order => 'created_at DESC', :limit => 20)
87 @title = "OpenStreetMap diary entries for #{user.display_name}"
88 @description = "Recent OpenStreetmap diary entries from #{user.display_name}"
89 @link = "http://#{SERVER_URL}/user/#{user.display_name}/diary"
91 render :content_type => Mime::RSS
93 render :nothing => true, :status => :not_found
95 elsif params[:language]
96 @entries = DiaryEntry.find(:all, :include => :user,
97 :conditions => ["users.visible = ? AND diary_entries.language = ?", true, params[:language]],
98 :order => 'created_at DESC', :limit => 20)
99 @title = "OpenStreetMap diary entries in #{params[:language]}"
100 @description = "Recent diary entries from users of OpenStreetMap"
101 @link = "http://#{SERVER_URL}/diary/#{params[:language]}"
103 render :content_type => Mime::RSS
105 @entries = DiaryEntry.find(:all, :include => :user,
106 :conditions => ["users.visible = ?", true],
107 :order => 'created_at DESC', :limit => 20)
108 @title = "OpenStreetMap diary entries"
109 @description = "Recent diary entries from users of OpenStreetMap"
110 @link = "http://#{SERVER_URL}/diary"
112 render :content_type => Mime::RSS
117 user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
120 @entry = DiaryEntry.find(:first, :conditions => ['user_id = ? AND id = ?', user.id, params[:id]])
122 @title = "Users' diaries | #{params[:display_name]}"
124 render :action => 'no_such_entry', :status => :not_found
127 @not_found_user = params[:display_name]
129 render :action => 'no_such_user', :status => :not_found