Class: Labimotion::CollectionsElement

Inherits:
ApplicationRecord
  • Object
show all
Includes:
Collecting, Tagging
Defined in:
lib/labimotion/models/collections_element.rb

Class Method Summary collapse

Class Method Details

.create_in_collection(eids, to_col_ids, element_type = '') ⇒ Object



34
35
36
37
38
39
40
# File 'lib/labimotion/models/collections_element.rb', line 34

def self.create_in_collection(eids, to_col_ids, element_type='')
  element_ids = Labimotion::Element.get_associated_elements(eids)
  sample_ids = Labimotion::Element.get_associated_samples(element_ids)
  static_create_in_collection(element_ids, to_col_ids)
  CollectionsSample.create_in_collection(sample_ids, to_col_ids)
  update_tag_by_element_ids(element_ids)
end

.get_elements_by_collection_type(collection_ids, type) ⇒ Object



13
14
15
# File 'lib/labimotion/models/collections_element.rb', line 13

def self.get_elements_by_collection_type(collection_ids, type)
  self.where(collection_id: collection_ids, element_type: type).pluck(:element_id).compact.uniq
end

.move_to_collection(eids, from_col_ids, to_col_ids, element_type = '') ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/labimotion/models/collections_element.rb', line 25

def self.move_to_collection(eids, from_col_ids, to_col_ids, element_type='')
  element_ids = Labimotion::Element.get_associated_elements(eids)
  sample_ids = Labimotion::Element.get_associated_samples(element_ids)
  delete_in_collection(element_ids, from_col_ids)
  static_create_in_collection(element_ids, to_col_ids)
  CollectionsSample.move_to_collection(sample_ids, from_col_ids, to_col_ids)
  update_tag_by_element_ids(element_ids)
end

.remove_in_collection(eids, from_col_ids) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/labimotion/models/collections_element.rb', line 17

def self.remove_in_collection(eids, from_col_ids)
  element_ids = Labimotion::Element.get_associated_elements(eids)
  sample_ids = Labimotion::Element.get_associated_samples(element_ids)
  delete_in_collection(element_ids, from_col_ids)
  update_tag_by_element_ids(element_ids)
  CollectionsSample.remove_in_collection(sample_ids, from_col_ids)
end