Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 8216e3bee8
Fetching contributors…

Cannot retrieve contributors at this time

82 lines (58 sloc) 3.376 kb
$:.unshift File.dirname(__FILE__)
require 'category'
require 'ware'
class Interview < Resource
attr_accessor :id, :slug, :name, :summary, :credit_name, :credit_url, :answers, :is_published, :published_on, :date_create, :date_update
attr_accessor :categories, :wares
def initialize()
categories = []
wares = []
end
def self.fetch(query, options = {})
interviews = super(query, options)
interviews.each do |interview|
interview.categories = Category.for_interview(interview.id)
interview.wares = Ware.for_interview(interview.id) unless options[:summary]
end
interviews
end
def self.all(options = {})
options = {:summary => false}.merge!(options)
self.fetch("SELECT * FROM interviews ORDER BY published_on DESC", options)
end
def self.recent(options = {})
options = {:summary => false}.merge!(options)
fields = options[:summary] ? "id, slug, name, summary, is_published, published_on" : "*"
self.fetch("SELECT #{fields} FROM interviews WHERE is_published=1 ORDER BY published_on DESC LIMIT 10", options)
end
def self.with_slug(slug, options = {})
slug = self.escape(slug)
result = self.fetch("SELECT * FROM interviews WHERE slug='#{slug}'", options)
result.length < 1 ? false : result[0]
end
def self.by_year(year, options = {})
year = self.escape(year)
options = {:summary => false}.merge!(options)
fields = options[:summary] ? "id, slug, name, summary, is_published, published_on" : "*"
self.fetch("SELECT * FROM interviews WHERE year(published_on) = '#{year}' AND is_published=1 ORDER BY published_on DESC", options)
end
def self.for_category_slug(slug, options = {})
slug = self.escape(slug)
options = {:summary => false}.merge!(options)
fields = options[:summary] ? "i.id, i.slug, i.name, i.summary, i.is_published, i.published_on" : "i.*"
self.fetch("SELECT #{fields} FROM interviews AS i, interview_categories AS ic, categories AS c WHERE ic.interview_id=i.id AND ic.category_id=c.id AND c.slug = '#{slug}' AND i.is_published=1 ORDER BY i.published_on DESC", options)
end
def self.counts()
Interview.query("SELECT year(published_on) AS year, count(*) AS count FROM interviews WHERE is_published=1 GROUP BY year ORDER BY year DESC")
end
def to_markdown
markdown = self.answers
if self.wares.length > 0
markdown += "\n\n"
self.wares.each do |ware|
markdown += "[#{ware.slug}]: #{ware.url} \"#{ware.description}\"\n"
end
end
markdown
end
end
Jump to Line
Something went wrong with that request. Please try again.