Skip to content

Commit

Permalink
Merge pull request #1317 from NatLibFi/issue1263-fix-skosxl-tooltips
Browse files Browse the repository at this point in the history
Fix SKOS-XL tooltips
  • Loading branch information
joelit authored May 4, 2022
2 parents a5ef6c8 + e34ba25 commit d64ceba
Showing 9 changed files with 65 additions and 18 deletions.
17 changes: 5 additions & 12 deletions model/ConceptPropertyValueLiteral.php
Original file line number Diff line number Diff line change
@@ -92,21 +92,14 @@ public function hasXlProperties()
return !empty($resources);
}

public function getXlProperties()
public function getXlLabel()
{
$ret = array();
$graph = $this->resource->getGraph();
$resources = $graph->resourcesMatching('skosxl:literalForm', $this->literal);
foreach ($resources as $xlres) {
foreach ($xlres->properties() as $prop) {
foreach($graph->allLiterals($xlres, $prop) as $val) {
if ($prop !== 'rdf:type') {
$ret[$prop] = $val;
}
}
}
$labelResources = $graph->resourcesMatching('skosxl:literalForm', $this->literal);
foreach($labelResources as $labres) {
return new LabelSkosXL($this->model, $labres);
}
return $ret;
return null;
}

}
Binary file modified resource/translations/en/LC_MESSAGES/skosmos.mo
Binary file not shown.
Binary file modified resource/translations/fi/LC_MESSAGES/skosmos.mo
Binary file not shown.
3 changes: 3 additions & 0 deletions resource/translations/skosmos_en.po
Original file line number Diff line number Diff line change
@@ -877,3 +877,6 @@ msgstr "Notation"

msgid "skos:notation_help"
msgstr "Code that uniquely identifies a concept within a concept scheme."

msgid "Information"
msgstr "Information"
5 changes: 4 additions & 1 deletion resource/translations/skosmos_fi.po
Original file line number Diff line number Diff line change
@@ -878,4 +878,7 @@ msgid "skos:notation"
msgstr "Notaatio"

msgid "skos:notation_help"
msgstr "Tunniste, joka yksilöi käsitteen sanaston sisällä."
msgstr "Tunniste, joka yksilöi käsitteen sanaston sisällä."

msgid "Information"
msgstr "Tietoja"
3 changes: 3 additions & 0 deletions resource/translations/skosmos_sv.po
Original file line number Diff line number Diff line change
@@ -878,3 +878,6 @@ msgstr "Notation"

msgid "skos:notation_help"
msgstr "Kod som unikt identifierar ett begrepp i en vokabulär."

msgid "Information"
msgstr "Information"
Binary file modified resource/translations/sv/LC_MESSAGES/skosmos.mo
Binary file not shown.
20 changes: 20 additions & 0 deletions tests/ConceptPropertyValueLiteralTest.php
Original file line number Diff line number Diff line change
@@ -183,4 +183,24 @@ public function testGetContainsHtml() {
$lit = new ConceptPropertyValueLiteral($this->model, $this->vocab, $resmock, $litmock, 'skosmos:testType');
$this->assertTrue($lit->getContainsHtml());
}

/**
* @covers ConceptPropertyValueLiteral::getXlLabel
* @covers ConceptPropertyValueLiteral::hasXlProperties
*/
public function testGetXlLabel() {
$voc = $this->model->getVocabulary('xl');
$conc = $voc->getConceptInfo('http://www.skosmos.skos/xl/c1', 'en')[0];
$props = $conc->getProperties();
$vals = $props['skos:altLabel']->getValues();
$val = reset($vals);

$reified_vals = array();
if ($val->hasXlProperties())
{
$reified_vals = $val->getXlLabel()->getProperties();
}
$this->assertArrayHasKey('skosxl:literalForm', $reified_vals);
$this->assertArrayHasKey('skosxl:labelRelation', $reified_vals);
}
}
35 changes: 30 additions & 5 deletions view/concept-shared.twig
Original file line number Diff line number Diff line change
@@ -127,7 +127,7 @@
<a href="{{ propval.uri | link_url(propval.exvocab, request.lang, 'page', request.contentLang) }}">{{ propval.label }}</a>{% if propval.exvocab %} ({{ propval.vocabname }}){% endif %}
{% else %}
{% if propval.isReified %} {# e.g. skos:definition's with resource values #}
<span class="versal reified-property-value"><img src="resource/pics/about.png">{% if propval.notation %}<span class="versal">{{ propval.notation }} </span>{% endif %} {{ propval.label(request.contentLang) }}</span>
<span class="versal reified-property-value"><img alt="{{ "Information" | trans }}" src="resource/pics/about.png">{% if propval.notation %}<span class="versal">{{ propval.notation }} </span>{% endif %} {{ propval.label(request.contentLang) }}</span>
<div class="reified-tooltip">{% for key, val in propval.reifiedPropertyValues %}<p>{{ key }}: <a href="{{ val.uri | link_url(val.exvocab, request.lang, 'page', request.contentLang) }}">{{ val.label(request.contentLang) }}</a></p>{% endfor %}</div>
{% else %}
<a href="{{ propval.uri | link_url(propval.vocab, request.lang, 'page', request.contentLang) }}">{% if propval.notation %}<span class="versal">{{ propval.notation }} </span>{% endif %} {{ propval.label(request.contentLang) }}</a>
@@ -145,8 +145,25 @@
{% endif %}
{% elseif property.type == 'rdf:type' %}<p>{{ propval.label|trans }}</p>
{% else %} {# Literals (no URI), eg. alternative labels as properties #}
{% if propval.lang == request.contentLang or propval.lang == null or not request.contentLang and propval.lang == request.lang %}{% if propval.hasXlProperties %}<span class="reified-property-value xl-label"><img src="resource/pics/about.png"></span><div class="reified-tooltip">{% for key, val in propval.getXlProperties %}{% if key != 'rdf:type' and key != 'skosxl:literalForm' and val != '' %}<p>{{ key|trans }}: <span class="versal">{{ val }}</span></p>{% endif %}{% endfor %}</div>{% endif %}<span{% if property.type == 'skos:altLabel' %} class="replaced"{% endif %}>{% if propval.containsHtml %}{{ propval.label|raw }}{% else %}{{ propval.label }}{% endif %}{% if propval.lang and (request.contentLang and propval.lang != request.contentLang or explicit_langcodes) %} ({{ propval.lang }}){% endif %}{% if propval.datatype %} ({{ propval.datatype }}){% endif %}</span>
{% endif %}
{% if propval.lang == request.contentLang or propval.lang == null or not request.contentLang and propval.lang == request.lang %}
{% if propval.hasXlProperties %}
<span class="reified-property-value xl-label"><img alt="{{ "Information" | trans }}" src="resource/pics/about.png"></span>
<div class="reified-tooltip">
{% for key, val in propval.xlLabel.properties %}
{% if key != 'rdf:type' and key != 'skosxl:literalForm' %}
<p>{{ key|trans }}:
<span class="versal">{{ val }}</span>
</p>
{% endif %}
{% endfor %}
</div>
{% endif %}
<span{% if property.type == 'skos:altLabel' %} class="replaced"{% endif %}>
{% if propval.containsHtml %}{{ propval.label|raw }}{% else %}{{ propval.label }}{% endif %}
{% if propval.lang and (request.contentLang and propval.lang != request.contentLang or explicit_langcodes) %} ({{ propval.lang }}){% endif %}
{% if propval.datatype %} ({{ propval.datatype }}){% endif %}
</span>
{% endif %}
{% endif %}
</li>
{% endfor %}
@@ -167,8 +184,16 @@
<li class="row other-languages{% if loop.first %} first-of-language{% endif %}">
<div class="col-6 versal{% if value.type == "skos:altLabel" %} replaced{%else %} versal-pref{% endif %}">
{% if value.hasXlProperties %}
<span class="reified-property-value xl-label"><img src="resource/pics/about.png"></span>
<div class="reified-tooltip">{% for key, val in value.getXlProperties %}{% if key != 'rdf:type' and key != 'skosxl:literalForm' and val != '' %}<p>{{ key|trans }}: <span class="versal">{{ val }}</span></p>{% endif %}{% endfor %}</div>
<span class="reified-property-value xl-label"><img alt="{{ "Information" | trans }}" src="resource/pics/about.png"></span>
<div class="reified-tooltip">
{% for key, val in value.xlLabel.properties %}
{% if key != 'rdf:type' and key != 'skosxl:literalForm' %}
<p>{{ key|trans }}:
<span class="versal">{{ val }}</span>
</p>
{% endif %}
{% endfor %}
</div>
{% endif %}
{% if value.type == "skos:prefLabel" and value.lang in request.vocab.config.languages %}
<a href='{{ concept.uri|link_url(request.vocabid,request.lang, 'page', value.lang) }}' hreflang='{{ value.lang }}'>{{ value.label }}</a>

0 comments on commit d64ceba

Please sign in to comment.