Class: DcBigTable

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/dc_big_table.rb

Overview

Schema information

Collection name: dc_big_table : Big Table

_id BSON::ObjectId _id created_at Time created_at updated_at Time updated_at key String Key (ident) used to retrieve key/values description String description site_id BSON::ObjectId Data will be used only for defined site. If empty, then it is default for all sites in database. active Mongoid::Boolean This key is active created_by BSON::ObjectId created_by updated_by BSON::ObjectId updated_by dc_big_table_values Embedded:DcBigTableValue Values defined by this key

Big table is meant to be a common space for defining default choices for select fields on forms. Documents are organized as key-value pair with the difference that values for the key can be defined for every site and can also be localized.

Usage (as used in forms):

In the example administrator may help user by providing values that can be used on DcAd document position field by defining them in ads-position key of big table. Example is from dc_ads.yml form.

10:
 name: position
 type: text_with_select
 eval: dc_big_table 'ads-positions'
 html:
   size: 20

dc_big_table collection embeds many DcBigTableValue documents.

Class Method Summary collapse

Class Method Details

.choices4(key, site = nil, locale = nil) ⇒ Object

Will return possible choices for specified key prepared for usega in select input field.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/models/dc_big_table.rb', line 81

def self.choices4(key, site = nil, locale = nil)
  result = []
  choices = find_by(key: key, site: site)
  choices = find_by(key: key, site: nil) if site && choices.nil?
  if choices
    choices.dc_big_table_values.each do |choice| 
      description = choice.description
      if locale
        desc = choice.find_by('dc_big_table_values.locale' => locale)
        description = desc.value if desc
      end             
      result << [description, choice.value]
    end
  end
# Error if empty
  result = [[I18n.t('drgcms.error'),I18n.t('drgcms.error')]] if result.size == 0
  result.sort_alphabetical_by(&:first)
end