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.193 app/models/caboose/block_type_category.rb
caboose-cms-0.9.192 app/models/caboose/block_type_category.rb
caboose-cms-0.9.191 app/models/caboose/block_type_category.rb
caboose-cms-0.9.190 app/models/caboose/block_type_category.rb
caboose-cms-0.9.189 app/models/caboose/block_type_category.rb
caboose-cms-0.9.188 app/models/caboose/block_type_category.rb
caboose-cms-0.9.187 app/models/caboose/block_type_category.rb
caboose-cms-0.9.186 app/models/caboose/block_type_category.rb
caboose-cms-0.9.185 app/models/caboose/block_type_category.rb
caboose-cms-0.9.184 app/models/caboose/block_type_category.rb
caboose-cms-0.9.183 app/models/caboose/block_type_category.rb
caboose-cms-0.9.182 app/models/caboose/block_type_category.rb
caboose-cms-0.9.181 app/models/caboose/block_type_category.rb
caboose-cms-0.9.180 app/models/caboose/block_type_category.rb
caboose-cms-0.9.179 app/models/caboose/block_type_category.rb
caboose-cms-0.9.178 app/models/caboose/block_type_category.rb
caboose-cms-0.9.177 app/models/caboose/block_type_category.rb
caboose-cms-0.9.176 app/models/caboose/block_type_category.rb
caboose-cms-0.9.175 app/models/caboose/block_type_category.rb
caboose-cms-0.9.174 app/models/caboose/block_type_category.rb