Skip to content

Commit

Permalink
sorting concept property values with natural case sort when sortByNot…
Browse files Browse the repository at this point in the history
…ation is true, fixes #737
  • Loading branch information
henriyli authored and osma committed Aug 27, 2018
1 parent 8c65f39 commit 28edcb1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion model/Concept.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@ public function getProperties()
if ($superprop) {
$superprop = EasyRdf\RdfNamespace::shorten($superprop) ? EasyRdf\RdfNamespace::shorten($superprop) : $superprop;
}
$propobj = new ConceptProperty($prop, $proplabel, $superprop);
$notsort = $this->vocab->getConfig()->sortByNotation();
$propobj = new ConceptProperty($prop, $proplabel, $superprop, $notsort);

if ($propobj->getLabel() !== null) {
// only display properties for which we have a label
Expand Down
6 changes: 4 additions & 2 deletions model/ConceptProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ class ConceptProperty
private $values;
/** flag whether the values are sorted, as we do lazy sorting */
private $is_sorted;
private $sort_by_notation;

/**
* Label parameter seems to be optional in this phase.
* @param string $prop property type eg. 'rdf:type'.
* @param string $label
*/
public function __construct($prop, $label, $super=null)
public function __construct($prop, $label, $super=null, $notsort=false)
{
$this->prop = $prop;
$this->label = $label;
$this->values = array();
$this->is_sorted = true;
$this->super = $super;
$this->sort_by_notation = $notsort;
}

/**
Expand Down Expand Up @@ -86,7 +88,7 @@ private function sortValues()
{
if (!empty($this->values)) {
uksort($this->values, function($a, $b) {
return strcoll(strtolower($a),strtolower($b));
return $this->sort_by_notation ? strnatcasecmp($a, $b) : strcoll(strtolower($a),strtolower($b));
});
}
$this->is_sorted = true;
Expand Down

0 comments on commit 28edcb1

Please sign in to comment.