getPriorityMatch($specificPrices, $user, $pointSale); $specificPricesFilter = []; foreach ($specificPrices as $keySpecificPrice => $specificPrice) { if (($priorityMatchSpecificPrice && $specificPrice->$priorityMatchSpecificPrice($user, $pointSale)) || $specificPrice->matchFromQuantityOnly()) { $specificPricesFilter[] = $specificPrice; } } return $specificPricesFilter; } // getPriorityMatchOfSpecificPriceArray public function getPriorityMatch( array $specificPriceArray, User $user = null, PointSale $pointSale = null): ?string { $typeMatchArray = [ 'matchUser', 'matchUserGroup', 'matchPointSale', 'matchUserPointSale', 'matchUserGroupPointSale' ]; foreach($typeMatchArray as $typeMatch) { if($this->hasMatchOfType($specificPriceArray, $typeMatch, $user, $pointSale)) { return $typeMatch; } } return null; } public function hasMatchOfType( array $specificPriceArray, string $typeMatch, User $user = null, PointSale $pointSale = null): bool { foreach($specificPriceArray as $specificPrice) { if($specificPrice->$typeMatch($user, $pointSale)) { return true; } } return false; } public function matchUser(ProductPrice $productPrice, User $user = null, PointSale $pointSale = null): bool { return $user && $productPrice->id_user && !$productPrice->id_point_sale && !$productPrice->id_user_group && $productPrice->id_user == $user->id; } public function matchUserGroup(ProductPrice $productPrice, User $user = null, PointSale $pointSale = null): bool { return $user && $productPrice->id_user_group && !$productPrice->id_point_sale && !$productPrice->id_user && $user->belongsToUserGroup($productPrice->id_user_group); } public function matchPointSale(ProductPrice $productPrice, User $user = null, PointSale $pointSale = null): bool { return $pointSale && $productPrice->id_point_sale && !$productPrice->id_user && !$productPrice->id_user_group && $productPrice->id_point_sale == $pointSale->id; } public function matchUserPointSale(ProductPrice $productPrice, User $user = null, PointSale $pointSale = null): bool { return $pointSale && $user && $productPrice->id_point_sale && $productPrice->id_user && $productPrice->id_point_sale == $pointSale->id && $productPrice->id_user == $user->id; } public function matchUserGroupPointSale(ProductPrice $productPrice, User $user = null, PointSale $pointSale = null): bool { return $user && $pointSale && $productPrice->id_user_group && $productPrice->id_point_sale && !$productPrice->id_user && $user->belongsToUserGroup($productPrice->id_user_group) && $productPrice->id_point_sale == $pointSale->id; } public function matchFromQuantityOnly(ProductPrice $productPrice): bool { return !$productPrice->id_user && !$productPrice->id_point_sale && !$productPrice->id_user_group && $productPrice->from_quantity; } }