class Osm::Event::Column

Constants

SORT_BY

Public Instance Methods

delete(api) click to toggle source

Delete event column from OSM @param [Osm::Api] api The api to use to make the request @return [Boolean] whether the delete succedded

# File lib/osm/event.rb, line 695
def delete(api)
  require_ability_to(api, :write, :events, event.section_id)

  data = api.perform_query("events.php?action=deleteColumn&sectionid=#{event.section_id}&eventid=#{event.id}", {
    'columnId' => id
  })

  (ActiveSupport::JSON.decode(data['config']) || []).each do |i|
    return false if i['id'] == id
  end

  new_columns = []
  event.columns.each do |column|
    new_columns.push(column) unless column == self
  end
  event.columns = new_columns

  cache_write(api, ['event', event.id], event)
  return true
end
inspect() click to toggle source
# File lib/osm/event.rb, line 716
def inspect
  Osm.inspect_instance(self, options={:replace_with => {'event' => :id}})
end
update(api) click to toggle source

Update event column in OSM @param [Osm::Api] api The api to use to make the request @return [Boolean] if the operation suceeded or not

# File lib/osm/event.rb, line 667
def update(api)
  require_ability_to(api, :write, :events, event.section_id)

  data = api.perform_query("events.php?action=renameColumn&sectionid=#{event.section_id}&eventid=#{event.id}", {
    'columnId' => id,
    'columnName' => name,
    'pL' => label,
    'pR' => (parent_required ? 1 : 0),
  })

  (ActiveSupport::JSON.decode(data['config']) || []).each do |i|
    if i['id'] == id
      if i['name'].eql?(name) && (i['pL'].nil? || i['pL'].eql?(label)) && (i['pR'].eql?('1') == parent_required)
        reset_changed_attributes
          # The cached event will be out of date - remove it
          cache_delete(api, ['event', event.id])
          # The cached event attedance will be out of date
          cache_delete(api, ['event_attendance', event.id])
        return true
      end
    end
  end
  return false
end