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