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

SKOS::Base

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Concept::Base

#associated_objects_in_editing_mode, broader_tops, #concept_relations_by_id, #concept_relations_by_id=, #concept_relations_by_id_and_rank, edit_link_partial_name, #ensure_a_pref_label_in_the_primary_thesaurus_language, #ensure_distinct_versions, #ensure_exclusive_top_term, #ensure_no_pref_labels_share_the_same_language, #ensure_rooted_top_terms, #ensure_valid_rank_for_ranked_relations, for_dashboard, 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?, with_associations, with_pref_labels

Methods included from Iqvoc::Versioning

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

Class Method Details

.by_label_value(val) ⇒ Object



63
64
65
# File 'app/models/collection/base.rb', line 63

def self.by_label_value(val)
  includes(:labels).merge(Label::Base.by_query_value(val))
end

.by_origin(origin) ⇒ Object

********** Scopes



59
60
61
# File 'app/models/collection/base.rb', line 59

def self.by_origin(origin)
  where(:origin => origin)
end

.topsObject



67
68
69
70
# File 'app/models/collection/base.rb', line 67

def self.tops
  includes(:parent_collection_members).
    where("#{Collection::Member::Collection.table_name}.target_id IS NULL")
end

Instance Method Details

#additional_infoObject

********** Methods



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

def additional_info
  concepts.count
end

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



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

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).



156
157
158
159
160
161
162
163
# File 'app/models/collection/base.rb', line 156

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



116
117
118
119
# File 'app/models/collection/base.rb', line 116

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

#inline_member_collection_origins=(origins) ⇒ Object



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

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

#inline_member_collectionsObject



121
122
123
124
125
126
127
# File 'app/models/collection/base.rb', line 121

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

#inline_member_concept_originsObject



99
100
101
# File 'app/models/collection/base.rb', line 99

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

#inline_member_concept_origins=(origins) ⇒ Object



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

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

#inline_member_conceptsObject



103
104
105
106
107
108
109
# File 'app/models/collection/base.rb', line 103

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



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

def label
  pref_label
end

#regenerate_collection_membersObject



141
142
143
144
145
146
147
148
149
# File 'app/models/collection/base.rb', line 141

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



131
132
133
134
135
136
137
138
139
# File 'app/models/collection/base.rb', line 131

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



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

def to_param
  origin
end