public function compareTo(VocabElement $o) { // A position value overrides and trumps sortName // Otherwise, compare alphabetically against sortName // Then arbitrarily compare on Term Type, Concept, and Id $pos = 0; $oPosition = $o->getPosition(); if ($this->position != null) { $pos = $oPosition == null ? $this->position : $this->position - $oPosition; } else { if ($oPosition != null) { $pos = $oPosition; } } if ($pos == 0) { // Either positions are the same or null $pos = $this->sortName == $o->getSortName() ? 1 : 0; } if ($pos == 0) { $pos = $this->type == $o->getType() ? 1 : 0; } if ($pos == 0) { $pos = $this->subclass == $o->getSubclass() ? 1 : 0; } if ($pos == 0) { $pos = $this->uri == $o->getUri() ? 1 : 0; } return $pos; }