mirror of
https://github.com/friendica/friendica
synced 2025-04-25 08:30:11 +00:00
Add common relationship methods to Model\ContactRelation
- Introduce DBA::mergeConditions method - Replace GContact relationship method contents with Model\ContactRelation method calls
This commit is contained in:
parent
a6a23802b7
commit
24a82110fd
5 changed files with 425 additions and 117 deletions
|
@ -539,7 +539,7 @@ class DBA
|
|||
* Returns the SQL condition string built from the provided condition array
|
||||
*
|
||||
* This function operates with two modes.
|
||||
* - Supplied with a filed/value associative array, it builds simple strict
|
||||
* - Supplied with a field/value associative array, it builds simple strict
|
||||
* equality conditions linked by AND.
|
||||
* - Supplied with a flat list, the first element is the condition string and
|
||||
* the following arguments are the values to be interpolated
|
||||
|
@ -645,6 +645,34 @@ class DBA
|
|||
return $condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the provided conditions into a single collapsed one
|
||||
*
|
||||
* @param array ...$conditions One or more condition arrays
|
||||
* @return array A collapsed condition
|
||||
* @see DBA::collapseCondition() for the condition array formats
|
||||
*/
|
||||
public static function mergeConditions(array ...$conditions)
|
||||
{
|
||||
$conditionStrings = [];
|
||||
$result = [];
|
||||
|
||||
foreach ($conditions as $key => $condition) {
|
||||
$condition = self::collapseCondition($condition);
|
||||
|
||||
$conditionStrings[] = array_shift($condition);
|
||||
// The result array holds the eventual parameter values
|
||||
$result = array_merge($result, $condition);
|
||||
}
|
||||
|
||||
if (count($conditionStrings)) {
|
||||
// We prepend the condition string at the end to form a collapsed condition array again
|
||||
array_unshift($result, implode(' AND ', $conditionStrings));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SQL parameter string built from the provided parameter array
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue