-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace leandrogehlen\querybuilder; | ||
|
||
class RuleHelper | ||
{ | ||
|
||
/** | ||
* Adds a table prefix for any field in conditions if not existing | ||
* @param array $rules for Translator | ||
* @param string $prefix | ||
* @return array | ||
*/ | ||
public static function addPrefixToRules(array $rules, string $prefix) : array | ||
Check failure on line 14 in src/RuleHelper.php GitHub Actions / build (ubuntu-latest, 7.4)
Check failure on line 14 in src/RuleHelper.php GitHub Actions / build (ubuntu-latest, 7.4)
Check failure on line 14 in src/RuleHelper.php GitHub Actions / build (ubuntu-latest, 8.0)
Check failure on line 14 in src/RuleHelper.php GitHub Actions / build (ubuntu-latest, 8.0)
Check failure on line 14 in src/RuleHelper.php GitHub Actions / build (ubuntu-latest, 8.1)
Check failure on line 14 in src/RuleHelper.php GitHub Actions / build (ubuntu-latest, 8.1)
Check failure on line 14 in src/RuleHelper.php GitHub Actions / build (ubuntu-latest, 8.2)
Check failure on line 14 in src/RuleHelper.php GitHub Actions / build (ubuntu-latest, 8.2)
Check failure on line 14 in src/RuleHelper.php GitHub Actions / build (ubuntu-latest, 8.3)
|
||
{ | ||
if (!isset($rules['rules']) || !$rules['rules']) { | ||
return $rules; | ||
} | ||
|
||
$out = []; | ||
foreach ($rules['rules'] as $key => $rule) { | ||
if (isset($rule['condition'])) { | ||
$out[$key] = static::addPrefixToRules($rule, $prefix); | ||
} else { | ||
if(!str_contains($rule['field'], ".")) { | ||
$rule['field'] = "$prefix.".$rule['field']; | ||
} | ||
$out[$key] = $rule; | ||
} | ||
} | ||
$rules['rules'] = $out; | ||
return $rules; | ||
|
||
} | ||
|
||
|
||
|
||
|
||
} |