Class: C80NewsTz::RBlurb

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Defined in:
app/models/c80_news_tz/r_blurb.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.two_last_pubs_by_advr(advertiser_id) ⇒ Object

выдать массив с двумя последними публикациями указанного рекламодателя массив может содержать элементов: 0, 1, 2



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/c80_news_tz/r_blurb.rb', line 50

def self.two_last_pubs_by_advr(advertiser_id)
  s = "
    SELECT
      `c80_news_tz_r_blurbs`.*
    FROM
      `c80_news_tz_r_blurbs`
    INNER JOIN
      `c80_news_tz_advs_blurbs` ON `c80_news_tz_r_blurbs`.id = `c80_news_tz_advs_blurbs`.r_blurb_id
    WHERE
      `c80_news_tz_advs_blurbs`.r_advertiser_id = #{advertiser_id}
    ORDER BY
      `c80_news_tz_r_blurbs`.created_at DESC
    LIMIT 2;
  "

  result = self.find_by_sql(s)
  result

end

.where_rubric(rubric_slug) ⇒ Object

выдать публикации, принадлежащие указанной рубрике



44
45
46
# File 'app/models/c80_news_tz/r_blurb.rb', line 44

def self.where_rubric(rubric_slug)
  self.joins(:rubrics).where(:c80_news_tz_rubrics => {:slug => rubric_slug})
end

Instance Method Details

#company_logoObject

выдать логотип первого попавшегося рекламодателя если чего-то нету - выдаётся nil



122
123
124
125
126
127
128
129
130
# File 'app/models/c80_news_tz/r_blurb.rb', line 122

def 
  result = nil
  if r_advertisers.count > 0
    if r_advertisers.first..present?
      result = r_advertisers.first.
    end
  end
  result
end

#issue_idObject

выдать id первого попавшегося номера если номера у публикации нету - выдать невероятное число 999999



102
103
104
105
106
107
108
# File 'app/models/c80_news_tz/r_blurb.rb', line 102

def issue_id
  result = 999999
  if issues.count > 0
    result = issues.first.id
  end
  result
end

#issue_titleObject

выдать название номера, которому принадлежит новость если чего-то не хватает - выдаётся пустая строка



112
113
114
115
116
117
118
# File 'app/models/c80_news_tz/r_blurb.rb', line 112

def issue_title
  result = ""
  if issues.count > 0
    result = issues.first.number
  end
  result
end

#normalize_friendly_id(input) ⇒ Object



24
25
26
# File 'app/models/c80_news_tz/r_blurb.rb', line 24

def normalize_friendly_id(input)
  input.to_s.to_slug.normalize(transliterations: :russian).to_s
end

#photo_previewObject

выдать картинку, которая пойдёт в блок преьвю



71
72
73
74
75
76
77
78
# File 'app/models/c80_news_tz/r_blurb.rb', line 71

def photo_preview
  result = nil
  if fphotos.count > 0
    result = fphotos.first.image
  else
  end
  result
end

#rubric_idObject

выдать id первой попавшейся рубрики если рубрики у публикации нету - выдать невероятное число 999999



92
93
94
95
96
97
98
# File 'app/models/c80_news_tz/r_blurb.rb', line 92

def rubric_id
  result = 999999
  if rubrics.count > 0
    result = rubrics.first.id
  end
  result
end

#rubric_titleObject

выдать строку: title первой попавшейся рубрики если таковой нету - выдаётся пустая строка



82
83
84
85
86
87
88
# File 'app/models/c80_news_tz/r_blurb.rb', line 82

def rubric_title
  result = ""
  if rubrics.count > 0
    result = rubrics.first.title
  end
  result
end

#short_meta_descriptionObject



32
33
34
35
36
37
38
39
40
41
# File 'app/models/c80_news_tz/r_blurb.rb', line 32

def short_meta_description

  if full.present? && full.length > 0
    result = strip_tags(full[0..200]+"...")
  else
    result = nil
  end
  result

end

#slug_candidatesObject



28
29
30
# File 'app/models/c80_news_tz/r_blurb.rb', line 28

def slug_candidates
  [:title] + Array.new(6) {|index| [:title, index+2]}
end