Class: CamaleonCms::Media

Inherits:
CamaleonRecord show all
Defined in:
app/models/camaleon_cms/media.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CamaleonRecord

#cama_build_cache_key, #cama_fetch_cache, #cama_get_cache, #cama_remove_cache, #cama_set_cache

Class Method Details

.find_by_key(key) ⇒ Object

search file or folder by key



26
27
28
29
30
31
32
33
# File 'app/models/camaleon_cms/media.rb', line 26

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



17
18
19
20
21
22
23
# File 'app/models/camaleon_cms/media.rb', line 17

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



36
37
38
39
# File 'app/models/camaleon_cms/media.rb', line 36

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