Class: AlphabeticIndex
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AlphabeticIndex
- Defined in:
- app/models/alphabetic_index.rb
Overview
This model is used to represent an alphabetic index. It has specified acts_as_content_node from Acts::ContentNode::ClassMethods.
Specification
Attributes
-
title - The title of the alphabetic index.
-
content_type - The type of content this index should show
Preconditions
-
Requires the presence of title.
Constant Summary
- ALLOWED_CONTENT_TYPES =
%w( Page
Instance Method Summary (collapse)
-
- (Object) items(letter = 'A',, options = {})
Returns an alphabetic list of all the descendant Items of type ContentType of the parent.
Instance Method Details
- (Object) items(letter = 'A',, options = {})
Returns an alphabetic list of all the descendant Items of type ContentType of the parent.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/alphabetic_index.rb', line 32 def items(letter = 'A', = {}) if letter.present? if self.content_type.present? klass = self.content_type.constantize else klass = Page end conditions = node.parent.descendant_conditions conditions = ["(#{conditions.shift})" + " AND (UPPER(#{klass.table_name}.title) LIKE UPPER(?) OR (taggings.context = 'title_alternatives' AND UPPER(tags.name) LIKE UPPER(?)))", conditions, "#{letter}%", "#{letter}%"].flatten klass.find_accessible(:all, { :include => { :node => :base_tags }, :order => "CASE WHEN UPPER(#{klass.table_name}.title) LIKE UPPER('#{letter}%') THEN UPPER(#{klass.table_name}.title) ELSE UPPER(tags.name) END", :conditions => conditions }.merge()) end end |