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_categories(site_id = nil) ⇒ Object

Returns choices for all categories, prepared for tree_select input field



92
93
94
95
96
97
98
99
100
# File 'app/models/dc_category.rb', line 92

def self.choices4_categories(site_id=nil)
  qry = where(active: true)
# 
  ar = [nil]
  ar << site_id.id if site_id
  qry = qry.in(dc_site_id: ar)
#
  qry.inject([]) { |result, category| result << [category.name, category.id, category.parent, category.order] }
end

.choices4_ctype(site_id = nil) ⇒ Object

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



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

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_parent(site_id = nil) ⇒ Object

Returns all values vhich can be used as parent select field.



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

def self.values_for_parent(site_id=nil) #:nodoc:
  qry = where(active: true)
  qry = qry.and(dc_site_id: site_id.id) if site_id
  qry.sort(name: 1).inject([]) {|r,v| r << [v.name, v._id]} 
end