Class: Label::SKOSXL::Base
- Inherits:
-
Base
- Object
- Base
- Label::SKOSXL::Base
show all
- Includes:
- FirstLevelObjectValidations, Validations, Versioning
- Defined in:
- app/models/label/skosxl/base.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#origin_has_to_be_escaped, #pref_label_language, #referenced_published_concepts_have_main_language_pref_label
Class Method Details
.by_origin(origin) ⇒ Object
108
109
110
|
# File 'app/models/label/skosxl/base.rb', line 108
def self.by_origin(origin)
where(origin: origin)
end
|
.edit_link_partial_name ⇒ Object
160
161
162
|
# File 'app/models/label/skosxl/base.rb', line 160
def self.edit_link_partial_name
'partials/label/skosxl/edit_link_base'
end
|
.for_dashboard ⇒ Object
116
117
118
|
# File 'app/models/label/skosxl/base.rb', line 116
def self.for_dashboard
unpublished_or_follow_up.includes(:locking_user)
end
|
.new_link_partial_name ⇒ Object
156
157
158
|
# File 'app/models/label/skosxl/base.rb', line 156
def self.new_link_partial_name
'partials/label/skosxl/new_link_base'
end
|
.search_result_partial_name ⇒ Object
152
153
154
|
# File 'app/models/label/skosxl/base.rb', line 152
def self.search_result_partial_name
'partials/label/skosxl/search_result'
end
|
.single_query(params = {}) ⇒ Object
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'app/models/label/skosxl/base.rb', line 122
def self.single_query(params = {})
query_str = build_query_string(params)
scope = by_query_value(query_str).
by_language(params[:languages].to_a).includes(:concepts).references(:concepts)
published.
order("LOWER(#{Label::Base.table_name}.value)")
if params[:collection_origin].present?
collection = Collection::Base.where(origin: params[:collection_origin]).last
if collection
scope = scope.includes(concepts: [ collections: { collection_members: :collection } ])
scope = scope.where("#{Collection::Member::Base.table_name}.collection_id" => collection.id)
else
raise "Collection with Origin #{params[:collection_origin]} not found!"
end
end
case params[:for]
when 'concept'
scope = scope.includes(:concepts).merge(Iqvoc::Concept.base_class.published)
when 'collection'
scope = scope.includes(:concepts).merge(Iqvoc::Collection.base_class.published)
end
scope = yield(scope) if block_given?
scope.map { |result| SearchResult.new(result) }
end
|
.with_associations ⇒ Object
112
113
114
|
# File 'app/models/label/skosxl/base.rb', line 112
def self.with_associations
includes(labelings: :owner)
end
|
Instance Method Details
#associated_objects_in_editing_mode ⇒ Object
Responsible for displaying a warning message about associated objects which are currently edited y another user.
222
223
224
225
226
|
# File 'app/models/label/skosxl/base.rb', line 222
def associated_objects_in_editing_mode
{
label_relations: Label::Relation::Base.by_domain(id).range_in_edit_mode
}
end
|
#build_rdf_subject(&block) ⇒ Object
174
175
176
177
178
|
# File 'app/models/label/skosxl/base.rb', line 174
def build_rdf_subject(&block)
ns = IqRdf::Namespace.find_namespace_class(self.rdf_namespace.to_sym)
raise "Namespace '#{rdf_namespace}' is not defined in IqRdf document." unless ns
IqRdf.build_uri(self.origin, ns.build_uri(self.rdf_class), &block)
end
|
#concepts_for_labeling_class(labeling_class) ⇒ Object
180
181
182
183
|
# File 'app/models/label/skosxl/base.rb', line 180
def concepts_for_labeling_class(labeling_class)
labeling_class = labeling_class.name if labeling_class < ActiveRecord::Base labelings.select{ |l| l.class.name == labeling_class.to_s }.map(&:owner)
end
|
#from_rdf(str) ⇒ Object
197
198
199
200
201
202
|
# File 'app/models/label/skosxl/base.rb', line 197
def from_rdf(str)
raise 'invalid rdf literal' unless str =~ /^"(.+)"(@(.+))$/
self.value = $1
self.language = $3
self
end
|
#from_rdf!(str) ⇒ Object
204
205
206
207
|
# File 'app/models/label/skosxl/base.rb', line 204
def from_rdf!(str)
from_rdf(str)
save(validate: false)
end
|
#has_concept_or_label_relations? ⇒ Boolean
213
214
215
216
217
218
|
# File 'app/models/label/skosxl/base.rb', line 213
def has_concept_or_label_relations?
Iqvoc::XLLabel.additional_association_classes.each do |association_class, foreign_key|
return true if send(association_class.name.to_relation_name).count > 0
end
end
|
#notes_for_class(note_class) ⇒ Object
164
165
166
167
|
# File 'app/models/label/skosxl/base.rb', line 164
def notes_for_class(note_class)
note_class = note_class.name if note_class < ActiveRecord::Base notes.select{ |note| note.class.name == note_class }
end
|
185
186
187
188
189
190
|
# File 'app/models/label/skosxl/base.rb', line 185
def related_labels_for_relation_class(relation_class, only_published = true)
relation_class = relation_class.name if relation_class < ActiveRecord::Base relations.select { |rel| rel.class.name == relation_class }
.map(&:range)
.select { |l| l.published? || !only_published }
end
|
#relations_for_class(relation_class) ⇒ Object
169
170
171
172
|
# File 'app/models/label/skosxl/base.rb', line 169
def relations_for_class(relation_class)
relation_class = relation_class.name if relation_class < ActiveRecord::Base relations.select{ |rel| rel.class.name == relation_class }
end
|
#to_param ⇒ Object
209
210
211
|
# File 'app/models/label/skosxl/base.rb', line 209
def to_param
origin
end
|