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.133 app/models/caboose/block_type_category.rb
caboose-cms-0.9.132 app/models/caboose/block_type_category.rb
caboose-cms-0.9.131 app/models/caboose/block_type_category.rb
caboose-cms-0.9.130 app/models/caboose/block_type_category.rb
caboose-cms-0.9.129 app/models/caboose/block_type_category.rb
caboose-cms-0.9.128 app/models/caboose/block_type_category.rb
caboose-cms-0.9.127 app/models/caboose/block_type_category.rb
caboose-cms-0.9.126 app/models/caboose/block_type_category.rb
caboose-cms-0.9.125 app/models/caboose/block_type_category.rb
caboose-cms-0.9.124 app/models/caboose/block_type_category.rb
caboose-cms-0.9.123 app/models/caboose/block_type_category.rb
caboose-cms-0.9.122 app/models/caboose/block_type_category.rb
caboose-cms-0.9.121 app/models/caboose/block_type_category.rb
caboose-cms-0.9.120 app/models/caboose/block_type_category.rb
caboose-cms-0.9.119 app/models/caboose/block_type_category.rb
caboose-cms-0.9.118 app/models/caboose/block_type_category.rb
caboose-cms-0.9.117 app/models/caboose/block_type_category.rb
caboose-cms-0.9.116 app/models/caboose/block_type_category.rb
caboose-cms-0.9.115 app/models/caboose/block_type_category.rb
caboose-cms-0.9.114 app/models/caboose/block_type_category.rb