<?php
/**
 * @package DJ-Catalog2-Yootheme
 * @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
 * @license http://www.gnu.org/licenses GNU/GPL
 * @author url: http://dj-extensions.com
 * @author email contact@dj-extensions.com
 */

namespace DJExtensions\DJCatalog2\YOOtheme\Builder\Source;
defined('_JEXEC') or die;
class ElementHelper
{
	// Used to remove duplicates & insert correct order values
	public static function shuffleOrder($orders)
	{
		//Check if there are duplicates
		if (count(array_diff_key($orders, array_unique($orders))) < 2) {
			return $orders;
		} else {
			foreach ($orders as $order => $key) {
				$ordersDuplicates = array_diff_key($orders, array_unique($orders));
				if (in_array($order, $ordersDuplicates)) {
					//This order number is duplicated
					$minValue = min($orders);
					//Search available value
					while (in_array($minValue, $orders)) {
						$minValue++;
					};
					$orders[$order] = $minValue;
				}
			}
			return $orders;
		}
	}
}

?>