/**
* 根据依赖关系排序
*
* @param array $fieldFeture 事情清单
* @param array $relationMapList 依赖关系清单
* @param array $relationRightValues 依赖关系值清单
*
* @return array
*/
public static function relationSort(array $fieldFeture, array $relationMapList, array $relationRightValues)
{
//从 事件清单 中拆分在 依赖关系值清单 中出现的数据
$sortFieldFeature = $unSortFieldFeature = [];
foreach ($fieldFeture as $val) {
if (in_array($val, $relationRightValues)) {
$unSortFieldFeature[] = $val; //出现过的值
} else {
$sortFieldFeature[] = $val; //未出现过的值
}
}
//从 依赖关系 清单中删除包含上一步未出现值的关系对(即键中包含未出现值的关系对)
unset($relationRightValues);
foreach ($relationMapList as $key => $item) {
foreach ($item as $ke => $val) {
if (in_array($ke, $sortFieldFeature)) {
unset($relationMapList[$key]);
} else {
$relationRightValues[] = $val;
}
}
}
if (isset($relationRightValues)) {
$relationRightValues = array_values(array_unique($relationRightValues));
}
if ($relationMapList && $unSortFieldFeature) {
$res = self::relationSort($unSortFieldFeature, $relationMapList, $relationRightValues);
$sortFieldFeature = ArrayHelper::merge($sortFieldFeature, $res);
} else {
//没有关系对时,返回剩余的 出现过的值
return ArrayHelper::merge($sortFieldFeature, $unSortFieldFeature);
}
return $sortFieldFeature;
}
07-02
3222