Class: Label::SKOSXL::Base

Inherits:
Base
  • Object
show all
Includes:
FirstLevelObjectValidations, Validations, Versioning
Defined in:
app/models/label/skosxl/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Validations

#origin_has_to_be_escaped, #referenced_published_concepts_has_to_be_valid

Class Method Details

.by_origin(origin) ⇒ Object

********** Scopes



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

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


142
143
144
# File 'app/models/label/skosxl/base.rb', line 142

def self.edit_link_partial_name
  'partials/label/skosxl/edit_link_base'
end

.for_dashboardObject



98
99
100
# File 'app/models/label/skosxl/base.rb', line 98

def self.for_dashboard
  unpublished_or_follow_up.includes(:locking_user)
end


138
139
140
# File 'app/models/label/skosxl/base.rb', line 138

def self.new_link_partial_name
  'partials/label/skosxl/new_link_base'
end

.search_result_partial_nameObject



134
135
136
# File 'app/models/label/skosxl/base.rb', line 134

def self.search_result_partial_name
  'partials/label/skosxl/search_result'
end

.single_query(params = {}) ⇒ Object

********** Methods



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'app/models/label/skosxl/base.rb', line 104

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

  # apply search entity type
  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_associationsObject



94
95
96
# File 'app/models/label/skosxl/base.rb', line 94

def self.with_associations
  includes(labelings: :owner)
end

Instance Method Details

#associated_objects_in_editing_modeObject

Responsible for displaying a warning message about associated objects which are currently edited y another user.



202
203
204
205
206
# File 'app/models/label/skosxl/base.rb', line 202

def associated_objects_in_editing_mode
  {
    label_relations: Label::Relation::Base.by_domain(id).range_in_edit_mode
  }
end

#build_rdf_subject(&block) ⇒ Object



156
157
158
159
160
# File 'app/models/label/skosxl/base.rb', line 156

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



162
163
164
165
# File 'app/models/label/skosxl/base.rb', line 162

def concepts_for_labeling_class(labeling_class)
  labeling_class = labeling_class.name if labeling_class < ActiveRecord::Base # Use the class name string
  labelings.select{ |l| l.class.name == labeling_class.to_s }.map(&:owner)
end

#from_rdf(str) ⇒ Object



177
178
179
180
181
182
# File 'app/models/label/skosxl/base.rb', line 177

def from_rdf(str)
  raise 'invalid rdf literal' unless str =~ /^"(.+)"(@(.+))$/
  self.value = $1
  self.language = $3
  self
end

#from_rdf!(str) ⇒ Object



184
185
186
187
# File 'app/models/label/skosxl/base.rb', line 184

def from_rdf!(str)
  from_rdf(str)
  save(validate: false)
end

#has_concept_or_label_relations?Boolean

Returns:

  • (Boolean)


193
194
195
196
197
198
# File 'app/models/label/skosxl/base.rb', line 193

def has_concept_or_label_relations?
  # Check if one of the additional association methods return elements
  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



146
147
148
149
# File 'app/models/label/skosxl/base.rb', line 146

def notes_for_class(note_class)
  note_class = note_class.name if note_class < ActiveRecord::Base # Use the class name string
  notes.select{ |note| note.class.name == note_class }
end


167
168
169
170
# File 'app/models/label/skosxl/base.rb', line 167

def related_labels_for_relation_class(relation_class)
  relation_class = relation_class.name if relation_class < ActiveRecord::Base # Use the class name string
  relations.select{ |rel| rel.class.name == relation_class }.map(&:range)
end

#relations_for_class(relation_class) ⇒ Object



151
152
153
154
# File 'app/models/label/skosxl/base.rb', line 151

def relations_for_class(relation_class)
  relation_class = relation_class.name if relation_class < ActiveRecord::Base # Use the class name string
  relations.select{ |rel| rel.class.name == relation_class }
end

#to_paramObject



189
190
191
# File 'app/models/label/skosxl/base.rb', line 189

def to_param
  origin
end