Class: DcCategory

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

Overview

Schema information

Collection name: dc_category : Categories

_id                  BSON::ObjectId       _id
created_at           Time                 created_at
updated_at           Time                 Last update
name                 String               Category name
description          String               Additional description of category
ctype                Integer              Category type. Could be used for grouping categories.
parent               BSON::ObjectId       Parent category. Leave blank if this is top level category.
active               Mongoid::Boolean     Category is active.
order                Integer              Additional order, which can be used for sorting.
created_by           BSON::ObjectId       created_by
updated_by           BSON::ObjectId       updated_by

Categories are used on DcPage documents for grouping documents. Categorization is most useful for grouping news, blog entries …

Class Method Summary collapse

Class Method Details

.choices4_ctype(site_id = nil) ⇒ Object

Returns values for category type. Values should be defined in BigTable on the site level all owerall.



75
76
77
78
79
80
81
82
83
84
85
# File 'app/models/dc_category.rb', line 75

def self.choices4_ctype(site_id=nil)
  site_id = site_id.id if site_id
  if DcBigTable.find_by(key: 'dc_category_type', :site.in => [site_id, nil])
    DcBigTable.choices4('dc_category_type', site_id)
  else
    opts = I18n.t('helpers.label.dc_category.choices4_ctype')
# not defined    
    return [] if opts.blank?
    opts.split(',').inject([]) {|result, e| result << e.split(':')}    
  end
end

.values_for_parentObject

Returns all values where parent value is nil (top level parent).



67
68
69
# File 'app/models/dc_category.rb', line 67

def self.values_for_parent #:nodoc:
  where(parent: nil).sort(name: 1).inject([]) {|r,v| r << [v.name, v._id]} 
end