Class Folder
In: app/models/folder.rb
Parent: ActiveRecord::Base

Folders can store another folders or Document’s.

Methods

External Aliases

childrens -> ar_childrens
mapping -> ar_mapping
documents -> ar_documents

Attributes

info  [rw]  Folder description
name  [rw]  Folder name
parent  [rw]  Parent folder

Public Class methods

All hierarchy’s root folder

[Source]

    # File app/models/folder.rb, line 56
56:   def self.find_root
57:     find_by_sql( sql_store.folder_find_root() ).first
58:   end

Public Instance methods

Returns array with sub-folders. If include_subfolders is false, only first-level childrens are returned

[Source]

    # File app/models/folder.rb, line 72
72:   def childrens(include_subfolders = true)
73:     return Folder.find_all([ 'hidden <> 1 AND folder_id = ?', self.id]) unless include_subfolders
74:     @_childrens ||= Folder.find_by_sql( sql_store.folder_find_all_childrens ).select { |f| f.l > self.l and f.r < self.r }
75:   end

Returns documents of this folder without iterating into sub-folders

[Source]

     # File app/models/folder.rb, line 114
114:   def documents(limit = nil)
115:     plainscanner().scan(limit)
116:   end

Iterates through documents of this folder, without iterating into subfolders.

[Source]

    # File app/models/folder.rb, line 93
93:   def each
94:     documents.each do |doc|
95:       yield doc
96:     end
97:   end

Iterates through sub-folders

[Source]

     # File app/models/folder.rb, line 211
211:   def each_folder # yields: folder
212:     self.childrens(false).each do |element|
213:       yield element
214:     end
215:   end

Check if this folder has no documents

[Source]

     # File app/models/folder.rb, line 119
119:   def empty?
120:     docscanner().count == 0
121:   end

Fetches all documents from the folder corresponding to "where to look for documents" field of the mapping

  <% for document in @folder.fetch_all %>
    <%= document.title %> in <%= document.folder_name %>
  <% end %>

[Source]

     # File app/models/folder.rb, line 132
132:   def fetch_all
133:     docscanner().scan_published(nil)
134:   end

Returns first num of documents from the Folder#fetch_all() result

[Source]

     # File app/models/folder.rb, line 145
145:   def fetch_first(num)
146:     docscanner().scan_published( [0, num ]  )
147:   end

Returns last num of documents from the Folder#fetch_all() result

[Source]

     # File app/models/folder.rb, line 150
150:   def fetch_last(num)
151:     start = docscanner().count_published - num
152:     if num > start
153:       start = 0
154:     end
155:     docscanner().scan_published( [ start, num ]  ).reverse
156:   end

Splits Folder#fetch_all() results using FolderPaginator class. Returns result for a given current_page

  <% for document in @folder.fetch_page(@params[:page]) %>
    <%= document.title %> in <%= document.folder_name %>
  <% end %>

[Source]

     # File app/models/folder.rb, line 140
140:   def fetch_page(current_page = nil)
141:     docscanner().scan_published(paginator(current_page).sql_limit)
142:   end

Check if this folder was created only to store some document’s parts

[Source]

     # File app/models/folder.rb, line 168
168:   def for_parts?
169:     hidden?
170:   end

Check if exact this folder has a mapping on it

[Source]

     # File app/models/folder.rb, line 163
163:   def has_direct_mapping?
164:     !ar_mapping.nil?
165:   end

[Source]

     # File app/models/folder.rb, line 158
158:   def has_mapping?
159:     !mapping.nil?
160:   end

[Source]

    # File app/models/folder.rb, line 64
64:   def hidden?
65:     self.hidden == 1
66:   end

Folder mapping’s index document

[Source]

    # File app/models/folder.rb, line 86
86:   def index
87:     mapping and mapping.index
88:   end

[Source]

     # File app/models/folder.rb, line 270
270:   def inspect
271:     "<Folder: #{id}; name: #{name}; root?: #{root?}; itemCount: #{itemCount}; [#{l},#{r}]>"
272:   end

Number of items stored in Folder (without subfolders)

[Source]

     # File app/models/folder.rb, line 173
173:   def itemCount
174:     self.childrens(false).length + self.count_documents
175:   end

Iterates through hierarchy under a given folder.

Example:

  <ul>
    <% @folder.iterate do |section, level, shift| %>
        <%= shift > 0 ? '<ul>' : '' %>
        <%= shift < 0 ? '</ul>' :'' %>
        <li><%= link_to section.name, :action => 'show', :id => section.id %></li>
    <% end %>
  </ul>

[Source]

     # File app/models/folder.rb, line 229
229:   def iterate # yields: folder, level, shift
230:     shift = 0
231:     prev_level = nil
232:     self.childrens.each do |folder|
233:         level = folder.indentation.to_i
234:         prev_level ||= level
235:         if prev_level < level then  shift = 1 end
236:         if prev_level > level then shift = -1 end
237:         if prev_level == level then shift = 0 end
238:         yield folder, level, shift
239:         prev_level = level
240:     end
241:   end

Returns mapping that covers this folder

[Source]

    # File app/models/folder.rb, line 80
80:   def mapping   
81:     sql = sql_store.folder_find_mapping(self.id)      
82:     Mapping.find_by_sql( sql ).first
83:   end

Returns FolderPaginator instance for a current_page

[Source]

     # File app/models/folder.rb, line 124
124:   def paginator(current_page)
125:     FolderPaginator.new(docscanner().count_published, mapping, current_page || 0)
126:   end

[Source]

    # File app/models/folder.rb, line 60
60:   def root?
61:     self.folder_id == 0
62:   end

[Validate]