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 = t 'diary_entry.new.title'
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= 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 if @diary_entry.update_attributes(params[:diary_entry])
36 redirect_to :controller => 'diary_entry', :action => 'view', :id => params[:id]
39 rescue ActiveRecord::RecordNotFound
40 render :action => "no_such_entry", :status => :not_found
44 @entry = DiaryEntry.find(params[:id])
45 @diary_comment = @entry.diary_comments.build(params[:diary_comment])
46 @diary_comment.user = @user
47 if @diary_comment.save
48 Notifier::deliver_diary_comment_notification(@diary_comment)
49 redirect_to :controller => 'diary_entry', :action => 'view', :display_name => @entry.user.display_name, :id => @entry.id
51 render :action => 'view'
56 if params[:display_name]
57 @this_user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
60 @title = t 'diary_entry.list.user_title', :user => @this_user.display_name
61 @entry_pages, @entries = paginate(:diary_entries,
62 :conditions => ['user_id = ?', @this_user.id],
63 :order => 'created_at DESC',
66 @title = t'diary_entry.no_such_user.title'
67 @not_found_user = params[:display_name]
69 render :action => 'no_such_user', :status => :not_found
71 elsif params[:language]
72 @title = t 'diary_entry.list.in_language_title', :language => Language.find(params[:language]).english_name
73 @entry_pages, @entries = paginate(:diary_entries, :include => :user,
74 :conditions => ["users.visible = ? AND diary_entries.language_code = ?", true, params[:language]],
75 :order => 'created_at DESC',
78 @title = t 'diary_entry.list.title'
79 @entry_pages, @entries = paginate(:diary_entries, :include => :user,
80 :conditions => ["users.visible = ?", true],
81 :order => 'created_at DESC',
89 if params[:display_name]
90 user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
93 @entries = DiaryEntry.find(:all, :conditions => ['user_id = ?', user.id], :order => 'created_at DESC', :limit => 20)
94 @title = "OpenStreetMap diary entries for #{user.display_name}"
95 @description = "Recent OpenStreetmap diary entries from #{user.display_name}"
96 @link = "http://#{SERVER_URL}/user/#{user.display_name}/diary"
98 render :nothing => true, :status => :not_found
100 elsif params[:language]
101 @entries = DiaryEntry.find(:all, :include => :user,
102 :conditions => ["users.visible = ? AND diary_entries.language_code = ?", true, params[:language]],
103 :order => 'created_at DESC', :limit => 20)
104 @title = "OpenStreetMap diary entries in #{Language.find(params[:language]).english_name}"
105 @description = "Recent diary entries from users of OpenStreetMap in #{Language.find(params[:language]).english_name}"
106 @link = "http://#{SERVER_URL}/diary/#{params[:language]}"
108 @entries = DiaryEntry.find(:all, :include => :user,
109 :conditions => ["users.visible = ?", true],
110 :order => 'created_at DESC', :limit => 20)
111 @title = "OpenStreetMap diary entries"
112 @description = "Recent diary entries from users of OpenStreetMap"
113 @link = "http://#{SERVER_URL}/diary"
118 user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
121 @entry = DiaryEntry.find(:first, :conditions => ['user_id = ? AND id = ?', user.id, params[:id]])
123 @title = t 'diary_entry.view.title', :user => params[:display_name]
125 render :action => 'no_such_entry', :status => :not_found
128 @not_found_user = params[:display_name]
130 render :action => 'no_such_user', :status => :not_found