Module: Notee::Helpers::NoteeHelper
- Defined in:
- lib/notee/helpers/notee_helper.rb
Instance Method Summary collapse
- #archive_notees(year, month) ⇒ Object
- #category_notees(search_txt) ⇒ Object
- #notee(search_txt) ⇒ Object
- #notee_archives ⇒ Object
- #notee_categories ⇒ Object
- #notee_comments(post_id) ⇒ Object
- #notee_set_meta_by_post(post) ⇒ Object
- #notee_writers ⇒ Object
- #notees ⇒ Object
- #writer_notees(name_or_id) ⇒ Object
Instance Method Details
#archive_notees(year, month) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/notee/helpers/notee_helper.rb', line 36 def archive_notees(year, month) if month tmp_month = (month.to_s.size != 2 ? "0" : "") + month.to_s tmp_date = year.to_s + tmp_month + "01" begin_time = Date.parse(tmp_date).beginning_of_month end_time = Date.parse(tmp_date).end_of_month else tmp_date = year.to_s + "0101" begin_time = Date.parse(tmp_date).beginning_of_year end_time = Date.parse(tmp_date).end_of_year end @posts = Notee::Post.where(published_at: begin_time..end_time).order(published_at: :desc) @posts end |
#category_notees(search_txt) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/notee/helpers/notee_helper.rb', line 24 def category_notees(search_txt) # search_by_category_slug category = Notee::Category.find_by(slug: search_txt) category = Notee::Category.find_by(name: search_txt) unless category return false unless category return false if category.is_deleted @posts = Notee::Post.where(category_id: category.id, status: Notee::STATUS[:published], is_deleted: false).order(published_at: :desc) @posts end |
#notee(search_txt) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/notee/helpers/notee_helper.rb', line 5 def notee(search_txt) return false unless search_txt post = Notee::Post.find_by(id: search_txt) post = Notee::Post.find_by(slug: search_txt) unless post return if post.status == Notee::STATUS[:draft] || post.status == Notee::STATUS[:deleted] || post.status == Notee::STATUS[:privated] || post.is_deleted == true post end |
#notee_archives ⇒ Object
69 70 71 72 |
# File 'lib/notee/helpers/notee_helper.rb', line 69 def notee_archives # DATA: {notee.time, notee.count} Notee::Post.find_by_sql("SELECT DATE_FORMAT(published_at, '%Y-%m') as time, count(*) as count FROM notee_posts WHERE status=1 and is_deleted=false GROUP BY DATE_FORMAT(published_at, '%Y-%m') ORDER BY time DESC;") end |
#notee_categories ⇒ Object
63 64 65 66 |
# File 'lib/notee/helpers/notee_helper.rb', line 63 def notee_categories # DATA: {notee.category.name, notee.count} Notee::Post.find_by_sql("SELECT category_id as category_id, count(*) as count FROM notee_posts WHERE notee_posts.status=1 and notee_posts.is_deleted=false GROUP BY category_id;") end |
#notee_comments(post_id) ⇒ Object
83 84 85 86 87 |
# File 'lib/notee/helpers/notee_helper.rb', line 83 def notee_comments(post_id) return if post_id.nil? @notee_comments = Notee::Comment.where(post_id: post_id, is_hidden: false, is_deleted: false) @notee_comments end |
#notee_set_meta_by_post(post) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/notee/helpers/notee_helper.rb', line 90 def (post) return { title: post.title, keyword: post.seo_keyword, description: post.seo_description, og_image: request.base_url + "/notee/" + post.thumbnail.content } end |
#notee_writers ⇒ Object
75 76 77 78 79 80 |
# File 'lib/notee/helpers/notee_helper.rb', line 75 def notee_writers users = Notee::User.where(is_deleted: false) writers = users.select { |user| user if user.posts.count > 0 }.map { |user| user } writers end |
#notees ⇒ Object
18 19 20 21 |
# File 'lib/notee/helpers/notee_helper.rb', line 18 def notees @posts = Notee::Post.where(status: Notee::STATUS[:published], is_deleted: false).order(published_at: :desc) @posts end |
#writer_notees(name_or_id) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/notee/helpers/notee_helper.rb', line 53 def writer_notees(name_or_id) writer = Notee::User.find_by(name: name_or_id) writer = Notee::User.find_by(name: name_or_id) unless writer return false unless writer return false if writer.is_deleted @posts = writer.posts end |