Bravo3\Orm\Services\RelationshipManager::updateMaintainedRelationshipSortIndices PHP Method

updateMaintainedRelationshipSortIndices() private method

Entities in a relationship that are not maintained (added or removed) will be updated when the entire relationship is added/removed
private updateMaintainedRelationshipSortIndices ( Relationship $inverse_relationship, string[] $maintain, Reader $reader, string $local_id )
$inverse_relationship Bravo3\Orm\Mappers\Metadata\Relationship Inverted relationship
$maintain string[] Array of foreign ID's that are the maintained part of the relationship
$reader Bravo3\Orm\Services\Io\Reader Local entity reader
$local_id string Local ID
    private function updateMaintainedRelationshipSortIndices(Relationship $inverse_relationship, $maintain, Reader $reader, $local_id)
    {
        if (!$inverse_relationship->getSortableBy()) {
            return;
        }
        // Update unchanged relationships, as the sort-by column or conditions may have changed
        foreach ($maintain as $foreign_id) {
            foreach ($inverse_relationship->getSortableBy() as $sortable) {
                $index_key = $this->getSortIndexKey($inverse_relationship, $sortable->getName(), $foreign_id);
                // Test conditions
                foreach ($sortable->getConditions() as $condition) {
                    if ($condition->getColumn()) {
                        if (!$condition->test($reader->getPropertyValue($condition->getColumn()))) {
                            // Condition failed, remove index
                            $this->getDriver()->removeSortedIndex($index_key, $local_id);
                            continue 2;
                        }
                    } elseif ($condition->getMethod()) {
                        if (!$condition->test($reader->getMethodValue($condition->getMethod()))) {
                            // Condition failed, remove index
                            $this->getDriver()->removeSortedIndex($index_key, $local_id);
                            continue 2;
                        }
                    }
                }
                // Add/update inverse index
                $this->getDriver()->addSortedIndex($index_key, $reader->getPropertyValue($sortable->getColumn()), $local_id);
            }
        }
    }