Sha256: 920ee61353aac9fd65e7380f2ff0e28cfdaf8771f053355efd95339bb3b6de35

Contents?: true

Size: 1.13 KB

Versions: 773

Compression:

Stored size: 1.13 KB

Contents

class Caboose::BlockTypeCategory < ActiveRecord::Base
  self.table_name = "block_type_categories"

  belongs_to :parent, :foreign_key => 'parent_id', :class_name => 'Caboose::BlockTypeCategory'  
  has_many :children, :foreign_key => 'parent_id', :class_name => 'Caboose::BlockTypeCategory', :dependent => :destroy, :order => :name
  has_many :block_types
  attr_accessible :id,
    :parent_id,
    :name 
    
  def self.layouts
    self.where("name = ? and parent_id is null", 'Layouts').reorder(:name).all
  end
  
  def self.content
    self.where("name = ? and parent_id is null", 'Content').reorder(:name).all
  end
  
  def self.rows
    cat = self.content
    return false if cat.nil?
    self.where("name = ? and parent_id = ?", 'Rows', cat.id).reorder(:name).all
  end
  
  def self.tree
    arr = []
    self.where("parent_id is null").reorder(:name).all.each do |cat|
      self.tree_helper(arr, cat, '')
    end
    return arr
  end
  
  def self.tree_helper(arr, cat, prefix)
    arr << { 'value' => cat.id, 'text' => "#{prefix}#{cat.name}" }
    cat.children.each do |kid|
      self.tree_helper(arr, kid, "#{prefix} - ")
    end
  end
  
end

Version data entries

773 entries across 773 versions & 1 rubygems

Version Path
caboose-cms-0.9.173 app/models/caboose/block_type_category.rb
caboose-cms-0.9.172 app/models/caboose/block_type_category.rb
caboose-cms-0.9.171 app/models/caboose/block_type_category.rb
caboose-cms-0.9.170 app/models/caboose/block_type_category.rb
caboose-cms-0.9.169 app/models/caboose/block_type_category.rb
caboose-cms-0.9.168 app/models/caboose/block_type_category.rb
caboose-cms-0.9.167 app/models/caboose/block_type_category.rb
caboose-cms-0.9.166 app/models/caboose/block_type_category.rb
caboose-cms-0.9.165 app/models/caboose/block_type_category.rb
caboose-cms-0.9.164 app/models/caboose/block_type_category.rb
caboose-cms-0.9.163 app/models/caboose/block_type_category.rb
caboose-cms-0.9.162 app/models/caboose/block_type_category.rb
caboose-cms-0.9.161 app/models/caboose/block_type_category.rb
caboose-cms-0.9.160 app/models/caboose/block_type_category.rb
caboose-cms-0.9.159 app/models/caboose/block_type_category.rb
caboose-cms-0.9.158 app/models/caboose/block_type_category.rb
caboose-cms-0.9.157 app/models/caboose/block_type_category.rb
caboose-cms-0.9.156 app/models/caboose/block_type_category.rb
caboose-cms-0.9.155 app/models/caboose/block_type_category.rb
caboose-cms-0.9.154 app/models/caboose/block_type_category.rb