Exemplo n.º 1
0
 public static function joinTables($table1Data, $table2Data, $key = "")
 {
     $indexes = ZuoraAPIHelper::getTableJoinKeyIndexes($table1Data, $table2Data, $key);
     return ZuoraAPIHelper::joinTablesWithIndexes($table1Data, $table2Data, $indexes[1], $indexes[2]);
     /*
             $index1 = -1;
             $counter1 = 0;
             $index2 = -1;
             foreach($table1Data[0] as $header1) {
                 $counter2 = 0;
     	    if (strlen($key) > 0) {
     		if (strcasecmp($key,$header1) != 0) {
     //	    	    print "Key Found: " . $key . " != " . $header1 . "<br/>\n";
                         $counter1++;
     		    continue;
                     }
     //	    	print "Key Found: " . $key . " == " . $header1 . "<br/>\n";
                 }
                 foreach ($table2Data[0] as $header2) {
     //	    	print "Header compare: " . $header1 . " == " . $header2 . "<br/>\n";
                 	if (strcasecmp($header1,$header2) == 0) {
                 	    $key = $header1;
                 	    $index1 = $counter1;
                 	    $index2 = $counter2;
     //	    	    print "Found Key: " . $key . ", index1: " . $index1 . ", index2: " . $index2 . "<br/>\n";
                 	    break;
                 	 }
                 	 $counter2++;
                 }
                 if ($index1 >= 0) {
                     break;
                 }
                 $counter1++;
             }
             $line = array();
             // Create the header.
             foreach($table1Data[0] as $header1) {
                 $line[] = $header1;
             }
             $counter = 0;
             foreach ($table2Data[0] as $header2) {
                 $line[] = $header2;
                 $counter++;
             }
             $output[] = $line;
     
             for ($i = 1; $i < count($table1Data); $i++) {
                 // Start the line
                 $line = array();
                 foreach($table1Data[$i] as $data1) {
                     $line[] = $data1;
                 }
     
                 $key1 = "";
                 if ($index1 >= 0) {
                     $key1 = $table1Data[$i][$index1];
                 }
                 for ($j = 1; $j < count($table2Data); $j++) {
                     $key2 = "";
                     if ($index2 >= 0) {
                         $key2 = $table2Data[$j][$index2];
                     }
                     $completeLine = $line;
     //		print "Data key compare: " . $key1 . " == " . $key2 . "<br/>\n";
                     if (strcasecmp($key1,$key2) == 0) {
     //		    print "Data key found: " . $key1 . "<br/>\n";
                         $counter = 0;
                         foreach ($table2Data[$j] as $data2) {
                             $completeLine[] = $data2;
                             $counter++;
                         }
                         $output[] = $completeLine;
                     }
                 }
             }
             return $output;
     */
 }