You are here

final public function PartyDefaultDataSet::reorderEntities in Party 7

Same name and namespace in other branches
  1. 8.2 includes/party.data.inc \PartyDefaultDataSet::reorderEntities()

Re-order attached entities

This will re-order any entities to match the order specified in $order. Any entities that are left out of $order will be appended to the new order. To remove an entity, use PartyData::detachEntity().

Parameters

array $order: A numeric array of old deltas in the new order

Return value

$this

File

includes/party.data.inc, line 959
Provides the default class for managing party - Attached entity relationships.

Class

PartyDefaultDataSet
Class PartyDefaultDataSet

Code

public final function reorderEntities($order) {

  // First we need to collect missed entities
  $missed_entities = array_diff_key($this->entities, array_fill_keys($order, TRUE));
  $entities = array();

  // Iterate over re-ordering our entities
  foreach ($order as $delta) {
    if (isset($this->entities[$delta])) {
      $entities[] = $this->entities[$delta];
    }
  }

  // Append any missed entities
  foreach ($missed_entities as $entity) {
    $entities[] = $entity;
  }

  // Store array values so we don't have any missed
  $this->entities = $entities;
  return $this;
}