Changeset 1694
- Timestamp:
- 05/02/08 09:52:20 (2 weeks ago)
- Files:
-
- trunk/app/controllers/admin/content_controller.rb (modified) (1 diff)
- trunk/app/controllers/admin/pages_controller.rb (modified) (1 diff)
- trunk/app/controllers/articles_controller.rb (modified) (2 diffs)
- trunk/app/controllers/comments_controller.rb (modified) (1 diff)
- trunk/app/models/article.rb (modified) (1 diff)
- trunk/app/models/content.rb (modified) (1 diff)
- trunk/app/models/page.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/admin/content_controller.rb
r1688 r1694 16 16 def list 17 17 # Filtering articles 18 conditions = " `contents`.id > 0"18 conditions = "contents.id > 0" 19 19 if params[:search] 20 20 @search = params[:search] trunk/app/controllers/admin/pages_controller.rb
r1688 r1694 90 90 def preview 91 91 headers["Content-Type"] = "text/html; charset=utf-8" 92 @page = this_blog.pages.build(params[:page])92 @page = Page.new(params[:page]) 93 93 data = render_to_string(:layout => "minimal") 94 94 data = Base64.encode64(data).gsub("\n", '') trunk/app/controllers/articles_controller.rb
r1693 r1694 69 69 70 70 set_headers 71 @comment = this_blog.comments.build(params[:comment])71 @comment = Comment.new(params[:comment]) 72 72 @controller = self 73 73 end … … 86 86 87 87 def view_page 88 if(@page = Page.find_by_name(params[:name] .to_a.join('/'), :conditions => "published = 1"))88 if(@page = Page.find_by_name(params[:name])) && @page.published? 89 89 @page_title = @page.title 90 90 else trunk/app/controllers/comments_controller.rb
r1669 r1694 25 25 26 26 set_headers 27 @comment = this_blog.comments.build(params[:comment])27 @comment = Comment.new(params[:comment]) 28 28 29 29 render :template => 'articles/comment_preview' trunk/app/models/article.rb
r1686 r1694 209 209 210 210 def self.find_by_published_at 211 find_by_sql("SELECT date_format(published_at, '%Y-%m') AS publication FROM contents WHERE published_at > 0 GROUP BY publication")211 super(:published_at) 212 212 end 213 213 trunk/app/models/content.rb
r1665 r1694 101 101 end 102 102 end 103 104 def find_by_published_at(column_name = :published_at) 105 from_where = "FROM #{self.table_name} WHERE #{column_name} > 0 AND type='#{self.name}'" 106 107 # Implement adapter-specific groupings below, or allow us to fall through to the generic ruby-side grouping 108 109 if self.connection.is_a?(ActiveRecord::ConnectionAdapters::MysqlAdapter) 110 # MySQL uses date_format 111 find_by_sql("SELECT date_format(#{column_name}, '%Y-%m') AS publication #{from_where} GROUP BY publication ORDER BY publication DESC") 112 113 elsif self.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) 114 # PostgreSQL uses to_char 115 find_by_sql("SELECT to_char(#{column_name}, 'YYYY-MM') AS publication #{from_where} GROUP BY publication ORDER BY publication DESC") 116 117 else 118 # If we don't have an adapter-safe conversion from date -> YYYY-MM, 119 # we'll do the GROUP BY server-side. There won't be very many objects 120 # in this array anyway. 121 date_map = {} 122 dates = find_by_sql("SELECT #{column_name} AS publication #{from_where}") 123 124 dates.map! do |d| 125 d.publication = Time.parse(d.publication).strftime('%Y-%m') 126 d.freeze 127 if !date_map.has_key?(d.publication) 128 date_map[d.publication] = true 129 d 130 end 131 end 132 dates.reject!{|d| d.blank? || d.publication.blank?} 133 dates.sort!{|a,b| b.publication <=> a.publication} 134 135 dates 136 end 137 end 103 138 end 104 139 trunk/app/models/page.rb
r1686 r1694 23 23 24 24 def self.find_by_published_at 25 find_by_sql("SELECT date_format(created_at, '%Y-%m') AS publication FROM contents WHERE type = 'Page' GROUP BY publication")25 super(:created_at) 26 26 end 27 27
