]> git.mxchange.org Git - mailer.git/blobdiff - inc/xml-functions.php
Hotfix
[mailer.git] / inc / xml-functions.php
index d59207e916ae0357fae647a85af646bc91a5673c..d09e8e11fae32792dc250b08d242ef77ec27cd19 100644 (file)
@@ -243,5 +243,62 @@ function convertXmlContion ($condition) {
        return $return;
 }
 
+// "Getter" for sql part back from given array
+function getSqlPartFromXmlArray ($columns) {
+       // Init SQL
+       $SQL = '';
+
+       // Walk through all entries
+       foreach ($columns as $columnArray) {
+               // Init SQL part
+               $sqlPart = '';
+
+               // Do we have a table/alias
+               if (!empty($columnArray['table'])) {
+                       // Pre-add it
+                       $sqlPart .= $columnArray['table'] . '.';
+               } // END - if
+
+               // Add column
+               $sqlPart .= '`' . $columnArray['column'] . '`';
+
+               // Is a function and alias set?
+               if ((!empty($columnArray['function'])) && (!empty($columnArray['alias']))) {
+                       // Add both
+                       $sqlPart = $columnArray['function'] . '(' . $sqlPart . ') AS `' . $columnArray['alias'] . '`';
+               } // END - if
+
+               // Add finished SQL part to the query
+               $SQL .= $sqlPart . ',';
+       } // END - foreach
+
+       // Return it without last commata
+       return substr($SQL, 0, -1);
+}
+
+// Searches in given XML array for value and returns the parent index
+function searchXmlArray ($value, $columns, $childKey) {
+       // Default is not found
+       $return = false;
+
+       // Walk through whole array
+       foreach ($columns as $key => $columnArray) {
+               // Make sure the element is there
+               assert(isset($columnArray[$childKey]));
+
+               // Now is it what we are looking for?
+               if ($columnArray[$childKey] == $value) {
+                       // Remember this match
+                       $return = $key;
+
+                       // And abort any further searches
+                       break;
+               } // END - foreach
+       } // END - foreach
+
+       // Return key/false
+       return $return;
+}
+
 // [EOF]
 ?>