]> git.mxchange.org Git - friendica.git/blobdiff - src/Database/DBA.php
Merge pull request #9044 from annando/avatar-stuff
[friendica.git] / src / Database / DBA.php
index f3edf52be5f1e973f940402db42ff6cc90b5d16b..46bd871b4a748838beeaf04f706b204f6369f6b2 100644 (file)
@@ -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
         *