Class: Osm::Event::Column

Inherits:
Model
  • Object
show all
Defined in:
lib/osm/event.rb,
lib/osm/event.rb

Overview

Ensure the constant exists for the validators

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#<, #<=, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i

Constructor Details

#initializeObject

Initialize a new Column



# File 'lib/osm/event.rb', line 445


Instance Attribute Details

#idString



431
# File 'lib/osm/event.rb', line 431

attribute :id, :type => String

#labelString



431
# File 'lib/osm/event.rb', line 431

attribute :id, :type => String

#nameString



431
# File 'lib/osm/event.rb', line 431

attribute :id, :type => String

#parent_requiredBoolean



431
# File 'lib/osm/event.rb', line 431

attribute :id, :type => String

Instance Method Details

#<=>(another) ⇒ Object

Compare Column based on event then id



503
504
505
506
507
# File 'lib/osm/event.rb', line 503

def <=>(another)
  result = self.event <=> another.try(:event)
  result = self.id <=> another.try(:id) if result == 0
  return result
end

#delete(api) ⇒ Boolean

Delete event column from OSM



481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
# File 'lib/osm/event.rb', line 481

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

#inspectObject



509
510
511
# File 'lib/osm/event.rb', line 509

def inspect
  Osm.inspect_instance(self, options={:replace_with => {'event' => :id}})
end

#update(api) ⇒ Boolean

Update event column in OSM



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
# File 'lib/osm/event.rb', line 453

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