diff --git a/src/Midgard/CreatePHP/Mapper/AbstractRdfMapper.php b/src/Midgard/CreatePHP/Mapper/AbstractRdfMapper.php index c49cdf6..4e48e60 100644 --- a/src/Midgard/CreatePHP/Mapper/AbstractRdfMapper.php +++ b/src/Midgard/CreatePHP/Mapper/AbstractRdfMapper.php @@ -154,4 +154,47 @@ public function canonicalName($className) { return $className; } + + /** + * This sort method is used for sorting elements in the given array according the reference array + * which contains some of the array keys of the first array. + * + * The method makes sure that array elements without a key in the reference stay in the array with + * a nearly stable order (i.e. what was before the elements in reference stays before, what was after + * stays after, what is in is ordered as in reference. + */ + public function sort($array, $reference) + { + $headIdx = 0; + $tailIdx = 0; + $i = 0; + foreach($array as $element) { + $i++; + if (false === array_search($element, $reference)) { + if (0 == $tailIdx) { + $headIdx = $i; + } + } else { + $tailIdx = $i; + } + } + + $toSort = array_splice($array, $headIdx); + $tail = array_splice($toSort, $tailIdx - $headIdx); + + for ($i=1; $i < count($toSort); $i++) { + $tempIdx = (int)array_search($toSort[$i], $reference); + $temp = $toSort[$i]; + $j = $i - 1; + + while ($j >= 0 && (int)array_search($toSort[$j], $reference) > $tempIdx){ + $toSort[$j + 1] = $toSort[$j]; + $j--; + } + + $toSort[$j+1] = $temp; + } + + return array_merge($array, $toSort, $tail); + } } \ No newline at end of file diff --git a/src/Midgard/CreatePHP/Mapper/DoctrinePhpcrOdmMapper.php b/src/Midgard/CreatePHP/Mapper/DoctrinePhpcrOdmMapper.php index fe1f3e8..b779d3e 100644 --- a/src/Midgard/CreatePHP/Mapper/DoctrinePhpcrOdmMapper.php +++ b/src/Midgard/CreatePHP/Mapper/DoctrinePhpcrOdmMapper.php @@ -206,47 +206,4 @@ public function getNodeName(&$item, $key) $item = PathHelper::getNodeName($item); } - /** - * This sort method is used for sorting elements in the given array according the reference array - * which contains some of the array keys of the first array. - * - * The method makes sure that array elements without a key in the reference stay in the array with - * a nearly stable order (i.e. what was before the elements in reference stays before, what was after - * stays after, what is in is ordered as in reference. - */ - public function sort($array, $reference) - { - $headIdx = 0; - $tailIdx = 0; - $i = 0; - foreach($array as $element) { - $i++; - if (false === array_search($element, $reference)) { - if (0 == $tailIdx) { - $headIdx = $i; - } - } else { - $tailIdx = $i; - } - } - - $toSort = array_splice($array, $headIdx); - $tail = array_splice($toSort, $tailIdx - $headIdx); - - for ($i=1; $i < count($toSort); $i++) { - $tempIdx = (int)array_search($toSort[$i], $reference); - $temp = $toSort[$i]; - $j = $i - 1; - - while ($j >= 0 && (int)array_search($toSort[$j], $reference) > $tempIdx){ - $toSort[$j + 1] = $toSort[$j]; - $j--; - } - - $toSort[$j+1] = $temp; - } - - return array_merge($array, $toSort, $tail); - } - } diff --git a/src/Midgard/CreatePHP/RestService.php b/src/Midgard/CreatePHP/RestService.php index 64f830f..174918c 100644 --- a/src/Midgard/CreatePHP/RestService.php +++ b/src/Midgard/CreatePHP/RestService.php @@ -206,7 +206,7 @@ private function _storeData($new_values, EntityInterface $entity) $expanded_name = $this->_expandPropertyName($rel, $entity); if (array_key_exists($expanded_name, $new_values)) { $expectedOrder = $new_values[$expanded_name]; - array_walk($expectedOrder, array($this, 'walkChildrenNames')); + array_walk($expectedOrder, array($this, 'walkJsonLdDecode')); $this->_mapper->orderChildren($entity, $node, $expectedOrder); } } elseif ($node instanceof PropertyInterface) { @@ -229,7 +229,7 @@ private function _storeData($new_values, EntityInterface $entity) return null; } - public function walkChildrenNames(&$item, $key) + public function walkJsonLdDecode(&$item, $key) { $item = $this->jsonldDecode($item); }