Class: Collection::Base

Inherits:
Concept::Base show all
Defined in:
app/models/collection/base.rb

Overview

Copyright 2011 innoQ Deutschland GmbH

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Direct Known Subclasses

Unordered

Instance Method Summary collapse

Methods inherited from Concept::Base

#additional_info, #associated_objects_in_editing_mode, #concept_relations_by_id, #concept_relations_by_id=, edit_link_partial_name, #ensure_a_pref_label_in_the_primary_thesaurus_language, #ensure_maximum_two_versions_of_a_concept, #ensure_no_pref_labels_share_the_same_language, #initialize, inline_partial_name, #invalid_with_full_validation?, #labelings_by_text, #labelings_by_text=, #labels_for_labeling_class_and_language, #matches_for_class, new_link_partial_name, #notes_for_class, #pref_label, #related_concepts_for_relation_class, #save_with_full_validation!, #to_s, #valid_with_full_validation?

Methods included from Iqvoc::Versioning

#branch, #editor_selectable?, #in_review?, #lock_by_user, #locked?, #publish, #published?, #state, #to_review, #unlock, #unpublish

Constructor Details

This class inherits a constructor from Concept::Base

Instance Method Details

#build_rdf_subject(document, controller, &block) ⇒ Object



86
87
88
# File 'app/models/collection/base.rb', line 86

def build_rdf_subject(document, controller, &block)
  IqRdf::Coll::build_uri(self.origin, IqRdf::Skos::build_uri("Collection"), &block)
end

#circular_subcollectionsObject

This only prevent circles of length 2.

# TODO: This shuold be a real circle detector (but still performant) or be

removed (seems to me like the better idea).



152
153
154
155
156
157
158
159
# File 'app/models/collection/base.rb', line 152

def circular_subcollections
  Iqvoc::Collection.base_class.by_origin(@member_collection_origins).each do |subcollection|
    if subcollection.subcollections.all.include?(self)
      errors.add(:base,
        I18n.t("txt.controllers.collections.circular_error") % subcollection.pref_label)
    end
  end
end

#inline_member_collection_originsObject



112
113
114
115
# File 'app/models/collection/base.rb', line 112

def inline_member_collection_origins
  @member_collection_origins || collection_members.
    map { |m| m.subcollection.origin }.uniq
end

#inline_member_collection_origins=(origins) ⇒ Object



107
108
109
110
# File 'app/models/collection/base.rb', line 107

def inline_member_collection_origins=(origins)
  @member_collection_origins = origins.to_s.
    split(Iqvoc::InlineDataHelper::Splitter).map(&:strip)
end

#inline_member_collectionsObject



117
118
119
120
121
122
123
# File 'app/models/collection/base.rb', line 117

def inline_member_collections
  if @member_collection_origins
    Collection::Base.where(:origin => @member_collection_origins)
  else
    subcollections
  end
end

#inline_member_concept_originsObject



95
96
97
# File 'app/models/collection/base.rb', line 95

def inline_member_concept_origins
  @member_concept_origins || concept_members.map { |m| m.concept.origin }.uniq
end

#inline_member_concept_origins=(origins) ⇒ Object



90
91
92
93
# File 'app/models/collection/base.rb', line 90

def inline_member_concept_origins=(origins)
  @member_concept_origins = origins.to_s.
    split(Iqvoc::InlineDataHelper::Splitter).map(&:strip)
end

#inline_member_conceptsObject



99
100
101
102
103
104
105
# File 'app/models/collection/base.rb', line 99

def inline_member_concepts
  if @member_concept_origins
    Concept::Base.editor_selectable.where(:origin => @member_concept_origins)
  else
    concepts.select{|c| c.editor_selectable?}
  end
end

#labelObject



82
83
84
# File 'app/models/collection/base.rb', line 82

def label
  pref_label
end

#regenerate_collection_membersObject



137
138
139
140
141
142
143
144
145
# File 'app/models/collection/base.rb', line 137

def regenerate_collection_members
  return if @member_collection_origins.nil? # There is nothing to do
  collection_members.destroy_all
  @member_collection_origins.each do |new_origin|
    Iqvoc::Collection.base_class.where(:origin => new_origin).each do |c|
      collection_members.create!(:target_id => c.id)
    end
  end
end

#regenerate_concept_membersObject

********** Hook methods



127
128
129
130
131
132
133
134
135
# File 'app/models/collection/base.rb', line 127

def regenerate_concept_members
  return if @member_concept_origins.nil? # There is nothing to do
  concept_members.destroy_all
  @member_concept_origins.each do |new_origin|
    Concept::Base.by_origin(new_origin).each do |c|
      concept_members.create!(:target_id => c.id)
    end
  end
end

#to_paramObject

********** Methods



78
79
80
# File 'app/models/collection/base.rb', line 78

def to_param
  origin
end