Class: Dhatu::Event

Inherits:
ApplicationRecord show all
Includes:
Featureable, Publishable
Defined in:
app/models/dhatu/event.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.save_row_data(hsh) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/dhatu/event.rb', line 35

def self.save_row_data(hsh)
  # Initializing error hash for displaying all errors altogether
  error_object = Kuppayam::Importer::ErrorHash.new

  return error_object if hsh[:title].to_s.strip.blank?

  event = Dhatu::Event.find_by_title(hsh[:title].to_s.strip) || Dhatu::Event.new
  event.title = hsh[:title].to_s.strip
  event.venue = hsh[:venue].to_s.strip
  event.description = hsh[:description].to_s.strip
  event.date = hsh[:date].to_s.strip
  event.starts_at = hsh[:starts_at].to_s.strip
  event.ends_at = hsh[:ends_at].to_s.strip
  
  # event.category = Dhatu::Category.find_by_name(hsh[:category])
  event.status = hsh[:status].to_s.strip || PUBLISHED
  event.featured = hsh[:featured].to_s.strip == "true"
  event.priority = hsh[:priority].to_s.strip || 1

  if event.valid?
    begin
      event.save!
    rescue Exception => e
      summary = "uncaught #{e} exception while handling connection: #{e.message}"
      details = "Stack trace: #{e.backtrace.map {|l| "  #{l}\n"}.join}"
      error_object.errors << { summary: summary, details: details }        
    end
  else
    summary = "Error while saving event: #{event.title}"
    details = "Error! #{event.errors.full_messages.to_sentence}"
    error_object.errors << { summary: summary, details: details }
  end
  return error_object
end

Instance Method Details

#can_be_deleted?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'app/models/dhatu/event.rb', line 92

def can_be_deleted?
  status?(:removed)
end

#can_be_edited?Boolean

Permission Methods


Returns:

  • (Boolean)


88
89
90
# File 'app/models/dhatu/event.rb', line 88

def can_be_edited?
  status?(:published) or status?(:unpublished)
end

#display_nameObject



81
82
83
# File 'app/models/dhatu/event.rb', line 81

def display_name
  "#{title_was}"
end

#to_paramObject

Generic Methods




77
78
79
# File 'app/models/dhatu/event.rb', line 77

def to_param
  "#{id}-#{title.parameterize[0..32]}"
end