Class: CamaleonCms::Media

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/camaleon_cms/media.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_key(key) ⇒ Object

search file or folder by key



23
24
25
26
27
28
29
30
# File 'app/models/camaleon_cms/media.rb', line 23

def self.find_by_key(key)
  key = key.cama_fix_media_key
  if key == '/'
    where(folder_path: File.dirname(key))
  else
    where(folder_path: File.dirname(key), name: File.basename(key))
  end
end

.search(search_expression = '', folder = nil) ⇒ Object



14
15
16
17
18
19
20
# File 'app/models/camaleon_cms/media.rb', line 14

def self.search(search_expression = '', folder = nil)
  if search_expression.blank?
    where(folder_path: folder)
  else
    where('name like ?', "%#{search_expression}%")
  end
end

Instance Method Details

#itemsObject

return all items of current folder



33
34
35
36
# File 'app/models/camaleon_cms/media.rb', line 33

def items
  coll = is_public ? site.public_media : site.private_media
  coll.where(folder_path: "#{folder_path}/#{name}".cama_fix_media_key)
end